npb consultants

IT Consultancy Services

  • Home
  • Downloads
  • Blog
  • Contact
  • Portal

Archive for April, 2009

List Number of Mailboxes per Exchange Server

Thursday, April 23rd, 2009

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

Posted in Powershell, Scripting | No Comments »

  • Search

  • You are currently browsing the There’s Geeks in the Bushes … blog archives for April, 2009.

  • 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.