Windows: Three ways to map a network drive using PowerShell

This subject is not directly related to virtualisation. However, it can be useful when you are not going to utilise Group Policy, and still need to automate drive mapping.

The old school

net use <drive_letter:> <UNC_path_to_the_network_drive> /persistent:[yes|no]

Pros: simple command that works.

Cons: not native to PowerShell; can be deprecated in the future.

Documentation: https://technet.microsoft.com/en-us/library/bb490717.aspx.

PowerShell 3.0+

New-PSDrive -Name <drive_name> -Root <UNC_path_to_the_network_drive> -PSProvider FileSystem -Scope [Global|Local] -Persist:[$true|$false]

New-PSDrive creates temporary and persistent mapped network drives. The scope should be set to allow other applications properly use mapped drives.

Pros: native to PowerShell.

Cons: require PowerShell 3.0+ to be fully functional.

Documentation: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-psdrive.

PowerShell 5.0+

New-SmbMapping -LocalPath <drive_letter:> -RemotePath <UNC_path_to_the_network_drive> -Persistent:[$true|$false]

New-SmbMapping creates a Server Message Block (SMB) mapping on the SMB client to an SMB share.

Pros: native to PowerShell.

Cons: this cmdlet had some issues before PowerShell 5.0.

Documentation: https://docs.microsoft.com/en-us/powershell/module/smbshare/new-smbmapping.

 

“The device cannot start. (Code 10)” for Microsoft ISATAP and Microsoft Teredo Tunneling adapters

I was checking the system settings for one of the Windows 2008 R2 virtual machines that had been provisioned from the template recently when ran over this issue.

Both Microsoft ISATAP Adapter and Microsoft Teredo Tunneling Adapter had warning icons in the Device Manager.

ipv6-issue-01

ipv6-issue-02

Even if it is a minor obstacle, I prefer to resolve any problems with the operating system before installing and configuring applications.

After searching on Microsoft web-site, I came to the following forum thread where the user named Dork Man pointed at the DisabledComponents registry value in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters registry hive.

In my case, it has been set to a value of 0xfffffff for some reason.

ipv6-issue-03

 

I found the Microsoft KB # 929852 that explained this parameter. In this article Microsoft states the following:

…system startup will be delayed for 5 seconds if IPv6 is disabled by incorrectly, setting the DisabledComponents registry setting to a value of 0xfffffff.

Microsoft supports only the following values to configure the IPv6 protocol:

  • 0 – re-enables all IPv6 components (Windows default setting)
  • 0xff – disables all IPv6 components except the IPv6 loopback interface
  • 0x20 – makes IPv4 preferable over IPv6 by changing entries in the prefix policy table
  • 0x10 – disables IPv6 on all non-tunnel interfaces (both LAN and PPP)
  • 0x01 – disables IPv6 on all tunnel interfaces
  • 0x11 – disables all IPv6 interfaces except for the IPv6 loopback interface.

I haven’t had any specific requirements for the setting. So changing the DisabledComponents registry value to 0 and rebooting the server resolved the problem completely.