Mapping Network Drives (Part 3)

by Aug 31, 2015

If you migrated from VBScript to PowerShell, you may remember how VBScript mapped network drives. This option is still available in PowerShell.

$helper = New-Object -ComObject WScript.Network

$helper.MapNetworkDrive('O:','\\dc-01\somefolder',$true) 
$helper.EnumNetworkDrives()

Test-Path -Path O:\
explorer.exe O:\
Get-PSDrive -Name O


$helper.RemoveNetworkDrive('O:', $true, $true) 

If you want to log on with alternate credentials, try this overload instead:

$helper.MapNetworkDrive('O:','\\dc-01\somefolder',$true, 'training\user02', 'topSecret') 

Twitter This Tip! ReTweet this Tip!