Friday, September 26, 2008

Free PowerShell commands for Active Directory

The good people of Quest have done it again...
On their site, you can freely download a set of predefined Windows PowerShell commands for Windows Active Directory management.
Together with a complete admin guide of 231 pages!

You can download the sources for this on the Quest site.

Here below is a sample script to create AD user accounts:

After you get it installed, you can start a regular PowerShell session and type:
Add-PSSnapIn Quest.ActiveRoles.ADManagement
This will extend the PowerShell for AD.

First we save the plaintext password as a AsSecureString:
PS C:\Users\yl.admin\Documents\PS> $pw = read-host "Enter password" -AsSecureString
Enter password: ********

Then connect to the targeted domain:
PS C:\Users\yl.admin\Documents\PS> Connect-QADService -service '' -ConnectionAccount 'xyz-stage\administrator' -ConnectionPassword $pw

Once you establish the connection to AD, you can import the csv file which has the below format:
Name Description
Svc_SP_IntrAP Intranet content web application pool
Svc_SP_IntrSSPAP Intranet farm shared services provider application pool

PS C:\Users\yl.admin\Documents\PS> import-csv C:\myworkspace\user.csv |%{new-qadUser -ParentContainer 'OU=Service Ac
ts,DC=xyz-stage,DC=com' -name $ -samAccountName $ -description $_.Description}

The accounts specified will show up in your AD.

No comments: