By David Wiseman (Administrator)Created 04 Mar 2008
My Rating:
Vote
Rating:
Not Rated
Views:5891
Downloads:73

Search for All Users Having a Specified Exchange Server

Language:  PowerShell

Compatibility

Windows XP Yes Windows 2003 Yes
Windows 2000 No Windows NT No
Vista Unknown Windows 2008 Unknown
Description

Sample script that searches Active Directory for all the users that have the Exchange server o=fabrikam/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=atl-msg-01. The msExchHomeServerName attribute is replicated to the Global Catalog. This means you can connect to a Global Catalog server and search across the forest for users having a specified Exchange server. This attribute is available only if you have installed Microsoft Exchange.

Code

Line Numbers: On  Off      Plain Text
$strFilter = "(&(objectCategory=User) `
    (msExchHomeServerName=/o=fabrikam/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=atl-msg-01))"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter

$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
    {$objItem = $objResult.Properties; $objItem.name}

 


Got a useful script? Click here to upload!


 

  Post Comment
Order By:  
User Comments
      
caryhenry
Posted On: 9/19/2019 2:13:43 AM

Back in late 2012 I was looking for examples of WMI related System Information. I came across this HTA application and liked its layout. My environment is a company with several thousand employees. Most are in main offices but there are those working at home or at remote sites. google street view maps Being able to support employees when not able to connect to their system maybe through a VPN connection because of a router problem even though they can get to the internet is difficult to diagnose without some information. If you would like to see an enhanced version of the system information tool that is of a similar layout to this one but gives the capability to save the results to a report and then print that out you might be interested in mine. I have also developed a version that can be run as a remote task job such as from SCCM or Altiris. The "No_GUI" version of the application can be modified IN CODE to indicate the output folder location and which sections of information should be stored (reported). To make it able to output information to the usual GUI and be able to save it as an HTML report I have excluded certain features that were included in this product such as stopping process and mapping shares. Those features I will put in a version that is for SUPPORT Employees only. Since the HTML / VBScript code for the .HTA(s) is always a work in progress and has made it up to 300KB in size, I will not post the code here, but invite you to check the file out at ftp://ftp.bae-soft.com or directly at ftp://ftp.bae-soft.com/BAE-Software_System_Information.zip

MartaSmith
Posted On: 9/20/2019 3:41:18 PM

The script of power shell was big headache for me. Thanks for this prepared script which ease my college project. I find https://paper-writing-service.reviews website very helpful in doing college projects to be completed on time.

SheliaSutton
Posted On: 10/9/2019 10:26:40 AM

So the training of the tools is not necessarily made you become a good multimedia designer. What is Graphic Design and Multimedia Design? street view

msflower
Posted On: 12/12/2019 7:28:23 AM

I love your blog! I am hoping to see more articles from you in the foreseeable future. Really great!!! helix jump