Script to Map Network Drive With credentials [Username and Password]

1 answer

Staff May 14, 2016

In a workgroup environment, this batch script will help you Map network drive with credentials.
 

net use <driver letter> \\<servername>\<sharename> /user:<username> <password>

Example:
 
net use w: \\myserver\share /user:jack MyPassword
 
VBS script example:
 

set Net = WScript.CreateObject(“WScript.Network”)
Net.MapNetworkDrive “<driveletter>”, “\\<servername>\<sharename>”, False, “<domain>\<userid>”, “<password>
 

Example:

set Net = WScript.CreateObject(“WScript.Network”)
Net.MapNetworkDrive “Z”, “\\SERVER\Share”, False, “SERVER\jack”, “password

 
With Powershell
 

$User = “user”
$PWord = ConvertTo-SecureString -String “password” -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
$net = $(New-Object -ComObject WScript.Network)
$net.MapNetworkDrive(“r:”, “\\server\share”)

#1

Please login or Register to Submit Answer

Social