npb consultants

IT Consultancy Services

  • Home
  • Downloads
  • Blog
  • Contact
  • Portal
« Querying WSUS with Powershell
Deploying Group Policy Preference Client Side Extensions for Windows XP via Group Policy »

List Number of Mailboxes per Exchange Server

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.

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($_)};

This entry was posted on Thursday, April 23rd, 2009 at 10:00 am and is filed under Powershell, Scripting. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Click here to cancel reply.

  • Search

  • Pages

    • Nick Brown
  • Archives

    • November 2009
    • April 2009
    • February 2009
    • January 2009
  • Categories

    • Open Audit (1)
    • Scripting (2)
      • Powershell (2)
    • Windows (2)
      • Deployment (1)
      • Vista (1)
 

©2007 All Rights Reserved.  •  Design by Free CSS Templates  •  Icons by FAMFAMFAM.