hello
Google
Welcome to Carpe Diem: Flaphead@Home Sign in | Join | Help

Carpe Diem: Flaphead.com

Seize the Day

News


  • Add to Technorati Favorites <script type="text/javascript" src="http://technorati.com/embed/3ni3q36ikc.js"> </script>
    This information is provided "AS IS" with no warranties, and confers no rights. Also some of the information contains my views and thoughts.
    <script src="http://widgets.technorati.com/t.js" type="text/javascript" charset="UTF-8"></script>

    Add Me! - Search Engine Optimization

    I heart FeedBurner

Exchange 2003 and Windows Powershell

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

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
}

Post using Windows Live Writer via my HTC Shift

Posted: 03 July 2008 20:28 by Paul Flaherty

Comments

subject: exchange said:

Tutorial: SAN storage for Microsoft Exchange Server How to access SharePoint sites through Microsoft

# July 5, 2008 13:18

wmi said:

# July 8, 2008 10:37
New Comments to this post are disabled