Another powershell script. This time making use of the .NET DirectorySearcher class. The title pretty much says it all – the output from the script lists each Exchange server in the organization with the number of mailboxes hosted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
function GetExchangeServers() { $RootPath = "LDAP://" + $RootDseObj.configurationNamingContext; $RootObj = New-Object DirectoryServices.DirectoryEntry $RootPath; $Selector = New-Object DirectoryServices.DirectorySearcher; $Selector.SearchRoot = $RootObj; $Selector.pagesize = 1000; $Selector.Sort.PropertyName = "name"; $Selector.filter = "(objectClass=msExchExchangeServer)"; $Results = $Selector.findall(); foreach($AdObj in $Results) { $AdObj.properties | Write-Output; } } function GetMailboxesOnServer($server) { $RootPath = "GC://" + $RootDseObj.rootDomainNamingContext; $RootObj = New-Object DirectoryServices.DirectoryEntry $RootPath; $Selector = New-Object DirectoryServices.DirectorySearcher; $Selector.SearchRoot = $RootObj; $Selector.pagesize = 1000; $Selector.filter = "(msExchHomeServerName="+$server["legacyexchangedn"]+")"; $Results = $Selector.findall(); $server["name"][0] + ": " + $Results.Count; } cls; $RootDseObj = New-Object DirectoryServices.DirectoryEntry "LDAP://RootDSE"; GetExchangeServers | foreach {GetMailboxesOnServer($_)}; |