The Active Directory drive (AD:) in PowerShell gives administrators an easy way to explore AD from the command line, in much the same way you would list the directory contents of a hard disk using the DIR command in DOS. Let’s see how to connect to the AD drive and the commands used to navigate through it.
You’ll see a list of the forest’s partitions. To do anything useful, we need to connect to the domain partition using the set-location cmdlet.
The distinguished name (DN) of your domain can be seen in the output of the previous DIR command. The DNS name of my Active Directory domain is ad.contoso.com, therefore the domain’s DN is dc=ad,dc=contoso,dc=com. So the command should look like Set-Location “dc=ad,dc=contoso,dc=com”. Again the PowerShell prompt will change, in this example to PS AD:\dc=ad,dc=contoso,dc=com>.
Note that if you want to change the working location to an Organizational Unit (OU) instead of a container, change cn to ou. For example, to connect to the HR OU, the command might look like Set-Location “ou=hr users”.
In exactly the same way you navigate back up a directory tree in DOS, you can use the set-location command to move back up a level. For example, to move from cn=users,dc=ad,dc=contoso,dc=com up one level to dc=ad,dc=contoso,dc=com, type set-location followed by two dots in the PowerShell window, like so: set-location ..
If you want to move in and out of the AD drive, or move around the AD drive but need to frequently return to a particular location, you can use the push-location and pop-location cmdlets: