I have been using this code for a while and thought I would post it.
I manage several Exchange 2003 servers, this PowerShell code will allow you to pull Mailbox data from each server into their own .CSV file.
It uses a built Array for the server list and parses the Array to get Mailbox data from each server.
$Mailboxes = $Null $Computers = "Server1","Server2","Server3","Server4" ForEach($Computer in $Computers) { $Mailboxes = Get-WmiObject -NameSpace Root\MicrosoftExchangeV2 -Class Exchange_Mailbox -Computer $Computer $Mailboxes | Export-Csv "C:\Mailboxes_$Computer.csv" -NoTypeInformation }
You can combine this with ADSI code to discover all your Exchange 2003 servers in your Directory.
This would give you Mailbox data on all of your Exchange 2003 servers without the need for a manual Array.
[Array]$ExchSrvs = @("") [String]$StrFilter = “(objectCategory=msExchExchangeServer)” $objRootDSE = [ADSI]“LDAP://RootDSE” [String]$strContainer = $objRootDSE.configurationNamingContext $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = New-object System.DirectoryServices.DirectoryEntry(”LDAP://$strContainer”) $objSearcher.PageSize = 1000 $objSearcher.Filter = $strFilter $objSearcher.SearchScope = “Subtree” $colServers = $objSearcher.FindAll() ForEach($objServer in $colServers) { [String]$Server = $objResult.Properties.name $ExchSrvs += $Server } $ExchSrvs.Count
Your final script would look something like this.
[Array]$ExchSrvs = @("") [String]$StrFilter = “(objectCategory=msExchExchangeServer)” $objRootDSE = [ADSI]“LDAP://RootDSE” [String]$strContainer = $objRootDSE.configurationNamingContext $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = New-object System.DirectoryServices.DirectoryEntry(”LDAP://$strContainer”) $objSearcher.PageSize = 1000 $objSearcher.Filter = $strFilter $objSearcher.SearchScope = “Subtree” $colServers = $objSearcher.FindAll() ForEach($objServer in $colServers) { [String]$Server = $objResult.Properties.name $Mailboxes = $Null $Mailboxes = Get-WmiObject -NameSpace Root\MicrosoftExchangeV2 -Class Exchange_Mailbox -Computer $Server $Mailboxes | Export-Csv "C:\Mailboxes_$Server.csv" -NoTypeInformation }
Hope this helps.
All information is provided on an AS-IS basis, with no warranties and confers no rights.
Tags: Exchange2003, Exchange_Mailboxes, PowerShell, WMI
