Tuesday, September 01, 2009
Get Mail Queue on all Hub Transport Servers
Get-TransportServer Get-Queue where-object {($_.MessageCount -gt 0)} sort messagecount -Descending Select -First 10
Thursday, January 08, 2009
Good Powershell script repository
Wednesday, October 29, 2008
Get disconnected mailboxes from Exchange 2003 servers
$list = Get-ExchangeServer where {$_.IsExchange2007OrLater -eq $False} `
%{gwmi -co $_ -namespace "root\MicrosoftExchangeV2" -query "SELECT * FROM Exchange_mailbox WHERE DateDiscoveredAbsentInDS IS NOT NULL"}
$list format-Table MailboxDisplayName,ServerName,StorageGroupName,StoreName -autosize out-file 2003_Mailbox.txt
Extract UPN from text file
####### extract-UPN.ps1
####### ::Tarun Arora
####### v1.0
####### This script will extract any UPN ending with $upn(variable below) from a text file
#######
####### Known Issue - If there is a email like user@UPN.com.au, it will extract that as well (not tested)
######################################################
## Update the relevant output file (containing the UPN's)
$outputFile = "c:\scripts\tarun\sortdata\UPN1.txt"
## Update the $ContentPath to the file you want to extract the UPN's
$contentPath= "c:\scripts\tarun\sortdata\content.txt"
## UPN suffix
$upn="@ABC"
################################################
## No need to change anything below this line
##################################################
$content = get-content $contentpath
write-output "UPN" | out-file $outputFile
$word=""
foreach ($line in $content)
{
$len=$line.length
if($len -gt 3)
{
for ($j=0; $j -lt $len;$j++)
{
$i = $line.substring($j,1)
$word=$word+$i
if($word.length -gt 5)
{
if($word.substring($word.length - 4,4) -ilike $upn){write-output $word | out-file $outputfile -append}
}
if(($i -eq " ") -OR ($i -eq [char]10) -OR ($i -eq [char]13) -OR ($i -eq " ")){$word=""}
}
$word=""
}
}
Monday, October 27, 2008
Active Sync Users with Device Partnership
Get-CASMailbox where {$_.HasActiveSyncDevicePartnership} select Name
Disable IMAP and POP3
Get-Mailbox –Server <ServerName> Set-CASMailbox –POPEnabled:$False
Get-Mailbox –Server <ServerName> Set-CASMailbox –IMAPEnabled:$False
Friday, October 24, 2008
GET Active Cluster Nodes
get-exchangeserver Where {$_.IsMemberOfCluster -match "yes"} | get-clusteredmailboxserverstatus | sort-object identity | select OperationalMachines
Command to count maiboxes
get-mailbox -result unlimited -Server <Servername> group database sort name ft -auto name, count
Thursday, October 23, 2008
All Stores Database Size and Mailbox Count
$exchangeservers = Get-ExchangeServer where-object {$_.Name -imatch "CCR" } Sort Name
$AllServers = @()
foreach ($server in $exchangeservers)
{
$db = Get-MailboxDatabase -server $server
foreach ($objItem in $db)
{
$edbfilepath = $objItem.edbfilepath
$Drive = $edbfilepath.DriveName
$DiskUsage = Get-WmiObject win32_logicaldisk -computerName $Server where-Object {$_.DeviceID -match $Drive}
$path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
$dbsize = Get-ChildItem $path
$start = $path.LastIndexOf('\')
$dbpath = $path.Substring($start +1).remove($path.Substring($start +1).length -4)
$mailboxpath = "$server\$dbpath"
$mailboxcount = Get-MailboxStatistics -database "$mailboxpath" measure-object
$ReturnedObj = New-Object PSObject
$ReturnedObj Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
$ReturnedObj Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
$ReturnedObj Add-Member NoteProperty -Name "Mailbox Count" -Value $mailboxcount.count
$ReturnedObj Add-Member NoteProperty -Name "Drive" -Value $Drive
$ReturnedObj Add-Member NoteProperty -Name "Disk Space (MB)" -Value ("{0:n0}" -f ($DiskUsage.Size/1024KB))
$ReturnedObj Add-Member NoteProperty -Name "Free Space (MB)" -Value ("{0:n0}" -f ($DiskUsage.FreeSpace/1024KB))
[float]$tempfloat = ($DiskUsage.FreeSpace/1000000)/($DiskUsage.Size/1000000)
$tempPercent = [math]::round(($tempfloat * 100),2)
$ReturnedObj Add-Member NoteProperty -Name "% Free" -Value $tempPercent
$AllServers += $ReturnedObj
}
}
$AllServers export-csv c:\DatabaseSize_MailBoxCount.csv -notype –force
Enable Circular Logging
Get-storagegroup –Server “servername” | Set-storagegroup –CircularLoggingEnabled $true
Find Disconnected Mailboxes
$clustnames = @("Server1 ",”Server2”)
$outputfile = "c:\powershell\disconnected.txt"
foreach ($clust in $clustnames)
{
"SERVER = " + $clust >> $outputfile
Get-MailboxStatistics -Server $clust where { $_.DisconnectDate -ne $null } select DisplayName,DisconnectDate >> $outputfile
"`r" >> $outputfile
}