In the original implementation of PowerShell, I was very discouraged with the lack of Active Directory support. SUre, you can create user accounts and Organizational units, but it was not easy. With PowerShell V2, that all changed with the addition on the Active Directory module. For the Microsoft Exam 70-640, I’m seeing a couple of changes. In the Maintaining the Active Directory Environment, I’m seeing PowerShell listed with no mention of the DS commands that are taught in The instructor lead course 6425B. Here are some tips on how to do the PowerShell equivalent of the DS commands.
DSQuery returns objects out of Active Directory. With DSQuery you can return information on objects in Active Directory
DSGet returns specified attributes of an object.
DSMod modifies specified attributes of an object.
DSAdd creates an object in the directory.
DSMove moves an object to a new container or OU.
DSRM removes an object, all multiple objects, from the directory.
PowerShell, with the Active Directory module installed, you can do all these things. So why make the change? Well, Microsoft is making the change. With the force the Microsoft is placing behind PowerShell, and how frequently it is listed on exam topics.
The first requirement is to install PowerShell V2. V2 is installed by default on Windows 7 and Server 2008 R2. This can be downloaded from Microsoft (http://support.microsoft.com/kb/968929). Once you have installed PowerShell V2, you also need to install the Remote Server Administrator Tools onto your client:
OK, now that all that work is done, start PowrShell. Type Import-Module ActiveDirectory. This will add 76 new cmdlets specifically for active directory into your PowerShell session. These cmdlets have a verb-noun syntax. For the verbs, you have:
Add – add an object to another object.
Enable – Enables an object
Get – returns an Active Directory object
Move – Moves an object
New – Creates as object.
Remove – Removes an object from Active Directory.
Set – Modifies the properties of an object.
For the Noun portion you have a lot more choices. Here are a few of them:
The DS commands were designed for command line / batch file management of Active Directory. For daily use, the GUI is still the best method, unless you have a very specific need. For example, let’s say you needed to move all the users from 5 different OUs to a single OU. There are 500 user objects in each OU, but only about 15 of them are in the SalesTeam group. How would you accomplish that with a GUI? That is why we still use a shell environment. For the sake of demonstration, the OU we want the user objects to end up in is called Indianapolis. It does not matter what OU they reside in. The group we want to filter on is called SalesTeam_GG. Here is the PowerShell command that will make this happen:
Get-ADGroupMember –identity SalesTeam_GG | Move-ADObject –Targetpath “OU=Indianapolis,DC=MCTNET,DC=com”
That’s it! PowerShell will first enumerate all the users in Active Directory that are members of the SalesTeam_GG group. Then those objects are sent to the Move-ADObject cmdlet and are sent to the Indianapolis OU. Try that in a GUI!
How do you know what each of these PowerShell cmdlets can do? Well, first let’s find them. Type Get-Command *-AD* and press Enter Most of the cmdlets listed here are Active Directory commands. PowerShell also has a very good built in help structure. Type in Get-Help Get-ADGroupMember –full. This will give you a description of the cmdlet, its syntax, parameters, and examples on how to use it.
Here is a simple comparison of some of the PowerShell commands vs an equivalent DS command:
|DS Command||PowerShell (not all of them)|
|DSGet||Same as above|
It would be a good idea to review these commands prior to taking the exam just to be safe.