I'm trying to map network drive on remote computer using Invoke-Command:
Invoke-Command -ComputerName servername -ScriptBlock { net use L: \\server\folder password /user:login}
but it doesn't work. Simple NET USE doesn't work either. I've also tried Powershell: how to map a network drive with a different username/password
So, how to run "cmd command" NET USE on remote computer? Or how to map network drive with powershell? Thank you
EDIT:
When I use
Invoke-Command -ComputerName servername -ScriptBlock { (New-Object -ComObject WScript.Network).MapNetworkDrive
("M:", "\\server\folder", $false, "login", "password") }
it will create some "shadow" disk that is visible only from remote computer using:
Invoke-Command -ComputerName servername -ScriptBlock { NET USE }
and can be deleted by using:
Invoke-Command -ComputerName servername -ScriptBlock { NET USE /d /y M: }
but I cannot see, delete or add mapped disc, that are visible when I connect to that remote server:(