Was tasked with getting some information out of Exchange 2003. Basically they wanted me to match up mailbox accounts with AD Users. The only consistent way to do this in our environment was to compare the LegacyDN property from the root\MicrosoftExchangeV2 - Exchange_Mailbox class with the AD User property LegacyExchangeDN. Following is the script used to iterate through our Exchange 2003 servers and generate an Excel report (CSV file).
- function Get-ExchangeInfo
- {
- BEGIN
- {
- $Start = Get-Date
- Write-Host "Script Started: $start`nProcessing"
- }
- PROCESS
- {
- $MailBoxes = Get-WmiObject `
- -namespace 'root\MicrosoftExchangeV2' `
- -class 'Exchange_MailBox' `
- -computerName $_ | sort size -desc | `
- Select MailBoxDisplayName, `
- ServerName, `
- StorageGroupName, `
- StoreName, `
- Size, `
- TotalItems, `
- legacyDN
- Write-Host "Server: $_"
- foreach($MailBox in $MailBoxes)
- {
- $ldap = "(LegacyExchangeDN={0})" -f $MailBox.legacyDN
- $User = Get-QADUser `
- -SizeLimit 0 `
- -IncludeAllProperties `
- -LdapFilter $ldap | `
- SELECT SamAccountName, Department, DisplayName
- $obj = New-Object psobject
- $obj | Add-Member NoteProperty SamAccountName $User.SamAccountName
- $obj | Add-Member NoteProperty Department $User.Department
- $obj | Add-Member NoteProperty DisplayName $User.DisplayName
- $obj | Add-Member NoteProperty Size $MailBox.Size
- $obj | Add-Member NoteProperty TotalItems $MailBox.TotalItems
- $obj | Add-Member NoteProperty ServerName $MailBox.ServerName
- $obj | Add-Member NoteProperty StorageGroupName $MailBox.StorageGroupName
- $obj | Add-Member NoteProperty StoreName $MailBox.StoreName
- $obj | Add-Member NoteProperty LegacyDN $MailBox.LegacyDN
- Write-Output $obj
- }
- }
- END
- {
- $End = Get-Date
- Write-Host "Script completed: $end"
- Write-Host "Total Duration: $($end-$Start).minute"
- }
- }
- Clear-Host
- $Servers = 'ms01','ms02','ms03','ms04','ms05','ms06'
- $Servers | Get-ExchangeInfo | Export-Csv -path 'c:\ExchangeInfo.csv' -noTypeInformation
Enjoy!
1 comment:
MS Exchange has many good facilties. But once I used one of them, and after that something happened with my program. Luckily I rapidly worked out the proper instrument for resolving. This tool showed how it would help with many like problems - reparar edb.
Post a Comment