Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Can anyone help me how to map a drive using powershell remotely.

I tried the below script

$computername = (Read-Host "Enter Remote computer to map a drive to")

Invoke-Command =scriptslock{
	$drivename = (Read-Host "Enter Drive Letter e.g. X:")
	$psprovider = (Read-Host "Enter psprovider e.g.filesystem")
	$server= (Read-Host "Name of the share you like to map")
	New-PSDrive $drivename -PSProvider -Root \\$server\$share -Persist -credential $admincredentials
} -ComputerName $computername


But it is creating the drive at local machine only.

Please share any idea on this.

Thank you
Posted

1 solution

Another option would be to use a client like WebDrive or Filezilla. My preference is WebDrive because it's more stable and versatile.


However, you are likely just missing something – running as Administrator when you should not be (or vice versa), or you didn’t set the scope to Global. You also may be forgetting the –Name switch to be entered into the code.

Here are some links that could be helpful for you:

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

http://serverfault.com/questions/673349/access-already-mapped-network-drive-in-powershell

http://heresjaken.com/scripting-a-mapped-network-drive-batch-vb-and-powershell/
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900