Monday, May 02, 2011

PowerShell–Querying Ad

Here is a simple script that you can run at the power-shell cmd line to get the properties associated with an AD user: (where JDoe is the AD userid)

(([directoryservices.directorysearcher] "(samaccountname=JDoe)").findall())[0].Properties

You can get at a particular property such as the objectId using the following statement:

[guid]((([directoryservices.directorysearcher] "(samaccountname=JDoe)").findall())[0].properties.getenumerator() | ? { $ -eq "objectguid"}).value[0]

No comments: