0

I have some automation scripts, but I had to split them down because of what appears to be an interesting bug. I've stripped it to its simplest form below:

Enter-PSSession [SERVER]
cd D:\

If I run the above in one go, I get the below error

cd : Cannot find drive. A drive with the name 'D' does not exist.

However, if I run the lines individually, they run fine. I have tried putting a sleep in for a second, a pause line, but still no luck. Is anyone else aware of this, and the way around it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Karl
  • 67
  • 1
  • 7

1 Answers1

1

Use Invoke-Command instead of enter-pssession.

Example:

$ReturnValue = Invoke-Command -ComputerName $Server -ScriptBlock{
    Set-Location D:
    # DO STUFF
    Return $ReturnValue # Return your stuff
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
guiwhatsthat
  • 2,349
  • 1
  • 12
  • 24