PowerShell will automatically create a PSDrive for the Active Directory domain that the client is a member of. An additional PSDrive can be created for a different domain in another forest.
First, make sure that the Active Directory PowerShell module is loaded.
Now you can create the connection with the New-PSDrive commandlet.
New-PSDrive ` –Name <PSDrive-Name> ` –PSProvider ActiveDirectory ` –Server "<Domain-Controller>" ` –Credential (Get-Credential "<User-Name>") ` –Root "//RootDSE/" ` -Scope Global
The new PSDrive can be used in several ways. Lets say that you have a test AD forest that you want to manage with PowerShell from a host joined to your production AD forest. The test forest has a domain controller named “dc-test-01.test.domain.com” that is providing the AD web service. The following command will create a PSDrive named “TEST” that will be connected to the “test.domain.com” domain.
If you’re going to run this cmd-let from a script you will have to make sure that you include the “-Scope Global” switch. Otherwise the PSDrive will be created within the scope of the script and will not be available to you in the shell.