Add a shared network drive mapping.

      objNetwork.MapNetworkDrive(strLocalDrive, strRemoteShare, [persistent], [strUser], [strPassword])

   objNetwork     : A WScript.network object

   strLocalDrive  : The drive letter (e.g. L:)
   strRemoteShare : The UNC path to the remote drive \\MyServer\MyPrinter
                    (String value)
   persistent     : True/False - store the mapping persistently in the users profile
                    default = false
   strUser        :  The user name. (Optional)
   strPassword    :  The password. (Optional)


Dim objNetwork, strRemoteShare
Set objNetwork = WScript.CreateObject("WScript.Network")
strRemoteShare = "\\myserver\users"
objNetwork.MapNetworkDrive "H:", strRemoteShare, False

To run these commands in PowerShell without calling cscript:

$network = New-Object -ComObject WScript.Network
$RemoteShare = '\\myserver\users'
$network.MapNetworkDrive('H:', $RemoteShare, $false)

The example script below takes this a stage further, disconnecting the drive letter first (and coded to cope with persistent and/or disconnected drive shares)

DriveMap.vbs - Connect a local drive letter to a remote file share

For workgroup machines sharing files via pass-thru authentication with no domain login script, a persistent drive map can be used. Persistent drives will automatically connect to the resource whenever it is available.

“The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side” ~ James Baldwin


NET, list drive mappings - .EnumNetworkDrives
NET, remove drive map - .RemoveNetworkDrive
Q138365 - Autodisconnect (Red cross)
Q305355 - Drives disconnected, and a red "X" appears

Equivalent Windows CMD command: NET - Manage network resources

© Copyright SS64.com 1999-2015
Some rights reserved