Reputation: 23
I am working on a remote machine from my desktop and I have the following script :
Invoke-Command -computername $name -authentification default -credential $creds1 -scriptblock {net use \share $password2 /user:otherdomain\otheruser}
Then I get A specified logon session does not exist. It may have already been terminated. This thing is frustrating because if I run net use \\share $password2 /user:otherdomain\otheruser
directly on the remote machine it works perfectly. Is there a workaround or did I miss something ?
Upvotes: 0
Views: 1251
Reputation: 200523
You need to pass the variable $password2
into the script block, otherwise its value will be empty:
Invoke-Command -Computer $name ... -ScriptBlock {
net use \\host\share $args[0] /user:otherdomain\otheruser
} -ArgumentList $password2
Upvotes: 0