I just have to share this with you, as I was quite impressed by how quick I knocked this script up. Basically I wanted to see how much email was queued up on my Exchange 2003 servers. I had a feeling that a WMI object existed so I ran scriptomatic on a server a behold under root\MicrosoftExchangeV2 was Exchange_SMTPQueue.
So the rest was easy. Using the built in Powershell command Get-WmiObject I was able to query an Exchange 2003 server for it's SMTP queues and message count:
Get-WmiObject -namespace "root\MicrosoftExchangeV2" Exchange_SMTPQueue -computername <Exchange2003Server>
So now all I needed to do was give it a list of servers to run this against. I came up with this. Now c:\ps\_PublicFolderServerList.txt is a CSV file with two columns, ServerName and Version. Version can be Exchange2000, Exchange2003 or Exchange2007
$Servers = Import-Csv "c:\ps\_PublicFolderServerList.txt"
$Server = $Servers | Sort-Object $_.ServerName $AllQ = @() $SrvList = @() ForEach ($Server in $Servers) { If ($Server.version -eq "Exchange2003") { $Srv = $Server.ServerName Write-host "Checking .. $Srv" $AllQ += Get-WmiObject -namespace "root\MicrosoftExchangeV2" Exchange_SMTPQueue -computername $Srv | where {$_.MessageCount -gt 0} | select VirtualMachine, QueueName, MessageCount } } $AllQ = $AllQ | Sort-Object $_.MessageCount
ForEach ($q in $AllQ) {
Write-Host $q.VirtualMachine -NonewLine Write-host ": Q Name=" -NonewLine Write-Host $q.QueueName -NoNewLine Write-host ": " -NonewLine Write-host $q.MessageCount }
Now if you have a mixed 2003/2007 environment, you can use the exchange snapin to dynamically get the Exchange 2003 servers. That looks like this, you can see the difference at the top. Now all I need is this in a GUI (I done this too and will blog later)
$Server = $Servers | Sort-Object $_.ServerName $AllQ = @() $SrvList = @()
$Servers = Get-ExchangeServer | where {$_.IsExchange2007OrLater -eq $False} $Servers = $Servers | Sort-Object $_.Name ForEach ($Server in $Servers) { $tmpMSXVer = $Server.AdminDisplayVersion.ToString() IF ($tmpMSXVer.IndexOf("6.5 (") -ge 0) { $Srv = $Server.Name
Write-host "Checking .. $Srv" $AllQ += Get-WmiObject -namespace "root\MicrosoftExchangeV2" Exchange_SMTPQueue -computername $Srv | where {$_.MessageCount -gt 0} | select VirtualMachine, QueueName, MessageCount } }
$AllQ = $AllQ | Sort-Object $_.MessageCount
Post using Windows Live Writer via my HTC Shift
Tutorial: SAN storage for Microsoft Exchange Server How to access SharePoint sites through Microsoft
PingBack from http://andrewplace.iifree.net/wmi.html