When you load the Active Directory Module, you get, by default, an Active Directory PSDrive for the current domain. You can avoid the drive from loading by setting $Env:ADPS_LoadDefaultDrive = 0. When writing scripts to export and import AD delegations, connecting to this remote drive became important to me. Here is an example of the code I used:
#Requires -module ActiveDirectory #Ensure the AD drive is available if ($Env:ADPS_LoadDefaultDrive -eq 0){ Remove-Module activedirectory -Force; $Env:ADPS_LoadDefaultDrive = 1 } Import-Module activedirectory -NoClobber Function Create-RemoteADDrive{ Param ( # DNS name of domain to connect to [Parameter(Mandatory=$true,Position=0)] $DNSDomain, [Switch]$ConnectToRoot ) #Remove drive if it exists if (Test-Path RemoteAD:){ SL c: ; Remove-PSDrive RemoteAD } $RemoteDomain = Get-ADDomain $DNSDomain $server = ($RemoteDomain).RidMaster if ($ConnectToRoot){ $Root = '' }ELSE{ #Connect to Default Naming Context $Root = ($RemoteDomain).DistinguishedName } #Note Scope is Script. If not set, disappears outside of function. Can set to Global New-PSDrive -Name "RemoteAD" -PSProvider ActiveDirectory -root $Root -server $server -Scope Script } #Example Create remote drive called RemoteAD for the default naming context of constoso.com, and change to that drive. Create-RemoteADDrive 'Contoso.com' SL RemoteAD: