Disable loading the default drive ‘AD:’ during import-module

All of you who have used the Active Directory (AD) powershell module would have noticed that every time you import the AD module, a default drive ‘AD:’ is also loaded. So when you type the following command:

Import-module ActiveDirectory

You see a progress bar with a message like following:

clip_image001[7]

Basically, during the import-module phase, the AD provider tries to mount a new drive with the name ‘AD’ targeting a Domain Controller (DC). It locates the DC by using the DsGetDcName APIs implemented by the Netlogon service. More information about DC location can be found here.

Upon finding a DC which satisfies certain conditions like the availability of the web service etc, the AD provider tries to mount a new drive targeting that DC. Let’s say that the name of the DC found is MyClosestDC.domain.com, then mounting the drive is similar to typing the following command:

New-PSDrive –Name “AD” –Root “” –PsProvider ActiveDirectory –server “MyClosestDC.domain.com”

Do note that the AD Provider targets the DC in the current machine’s domain. If a DC is not found, as in the case of a machine which is not domain joined, then the default drive is not created and a warning is displayed.

Disable the loading of the default drive

If for some reason, you want to disable the loading of the default drive, then all you have to do is set the value of the environment variable ‘ADPS_LoadDefaultDrive’ to ‘0’. In powershell, this can be achieved by typing the following command:

PS Env:\> $Env:ADPS_LoadDefaultDrive = 0

Now when you import the AD module, the default drive will not be loaded.

This is particularly useful when you are trying to invoke an ADPowershell cmdlet through a command line or vb/powershell script and do not want to load the drive. For example following can be run in a cmd window:

C:\Windows\System32> Powershell.exe –Command $Env:ADPS_LoadDefaultDrive=0; Import-Module ActiveDirectory; Get-ADUser muali -server MyDC;

clip_image003[4]

Please note the above powershell commands only effect the current user session. For a permanent change in the environment variables, use SETX as following:

PS C:\> SETX ADPS_LoadDefaultDrive 0 /M

Cheers,

Ali

---

Mudassir Ali

Software Development Engineer in Test – Active Directory Powershell Team

Comments

  • Anonymous
    April 17, 2010
    Am I incorrect in assuming this could be used as a means of specifying a non-default domain during the call to "import-module activedirectory?"  If the calling workstation is joined to domain "domain1.forest1.com", would something similar to the following connect to a DC in domain "domain2.forest2.com" (provided successful credential authentication)?<Psuedo Code>PS Env:> $Env:ADPS_LoadDefaultDrive = 0PS:>Import-Module ActiveDirectoryPS:>New-PSDrive –Name “AD” –Root “” –PsProvider ActiveDirectory –server “DC2.domain2.forest2.com”<End Psuedo Code>If yes...can you give example of cleaner way to do this.  If not...why?  Thanks.Paul B. (USAF)
  • Anonymous
    April 19, 2010
    Hello Paul,Yes you are right. Provided successful credential authentication, you can create a new drive to the "DC2.domain2.forest2.com". A couple of points though:You do not HAVE to disable the default drive loading. You can connect to a different domain by providing another name of the drive. For example:New-PSDrive -Name "Dom2" -Root ...Also, while creating a new drive, you can provide credential different from the ones you are logged in as. This is also true for any other ADPowershell cmdlets such as Get-ADUser etc. For example:New-PSDrive -Name "Dom3" -Root "" -PsProvider ActiveDirectory -Server "domain2.forest.com" -Credential "domainuser"Or$cred = Get-Credential "domainuser"Get-ADUser "user-sam-account-name" -Server "domain2" -Credential $credThanks,Ali
  • Anonymous
    January 17, 2012
    The Web Server Administration module for Windows PowerShell includes the Internet Information Services (IIS) cmdlets that let you manage the configuration and run-time data of IIS. It implements a namespace hierarchy containing Application Pools, Web sites, Web applications and virtual directories.The IIS module implements one virtual drive named IIS. The root virtual folders are AppPools and Sites. Within the AppPools folder, run-time data, such as the currently running worker processes, application domains, and requests can be found. The Sites folder contains Web site folders, as well as applications and virtual directories.By default, Windows PowerShell modules and snap-ins are not loaded in Windows PowerShell. To start Windows PowerShell so that all the Windows PowerShell modules and snap-ins are loaded automatically, right-click the Windows PowerShell icon in the taskbar, and then click Import all modules. In Windows Server 2008 R2, the Windows PowerShell icon is pinned to the taskbar by default. However, you must start Windows PowerShell one time to make the Import all modules task appear.You can manually add the IIS Module to the instance of Windows PowerShell that you have opened by using the following command at the command prompt: C:PS>add-pssnapin WebAdministration.http://www.lepide.com/
  • Anonymous
    May 05, 2012
    Best post. Thank you.Ngnwww.engincapat.com
  • Anonymous
    December 08, 2014
    The comment has been removed
  • Anonymous
    September 28, 2015
    Nice One. Helped me a lot