0

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 ?

mora
  • 23
  • 4
  • I have found by adding net session to my remote script that there is no entry. Does someone know how to manually add one ? – mora Jun 21 '13 at 16:35

1 Answers1

0

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
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328