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() | ? { $_.name -eq "objectguid"}).value[0]

No comments:

Post a Comment

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.