3

I have a complex powershell script that uses remoting and does a lot of file copying and loading and unloading of powershell modules. Within the script I use robocopy to move only changes files and anything works OK.

However, every now and then the powershell session gets into a weird state whereby it no longer executes external commands. For instance if I type robocopy into the console it just returns immediately with no error and no output. If I type whoami, it again returns immediately with no output. It only gets into this state about 1 in 10 executions of the same script.

If I close the console and start a new session everything goes back to normal. Any idea what's going in here? I can't figure out a way to debug or fix this state.

Thanks, Mike

Update It looks like there's a known issue with passing arrays to write-host that can cause this behavior. I don't believe I'm doing this, but it's difficult to know for sure. I've managed to put a trap in place testing when the result of whoami becomes empty. Oddly it appears to happen whilst waiting for a long running remote operation.

TheCodeKing
  • 19,064
  • 3
  • 47
  • 70
  • BTW I resolved by running scripts without verbose trace. It's unclear if this resolved the issue because of less content written to the console, or because it turned off a rogue trace. – TheCodeKing Aug 24 '11 at 21:40

3 Answers3

1

Unfortunately I don't have an answer for you, but I have also seen this exact behavior and I can add some insight; I know for a fact that I am not using write-host, and this problem only occurs when I use powershell V2's background jobs and remoting together. Typically this happens after I've run a fairly large number of background jobs, and just like you the problem is isolated to that single powershell process. Relaunching powershell always fixes the problem.

jbsmith
  • 1,616
  • 13
  • 10
0

For anyone else that may run into this - check all lines that have write-host - in my case the culprit was this line in the script:

Write-Host **************************************

It was used at the end as a visual marker that all loops have completed and below it there was a summary... As soon as I remove it, the commands execute. If I add it, they stop executing... Maybe the asterisks overflow some buffer? Not sure but I will never use them again... :)

  • 1
    Interesting I'm not using `****` in traces. I tried printing this 1000 times to the console but it doesn't reproduce the issue. – TheCodeKing Sep 16 '11 at 20:34
0

If you are using /R option with the robocopy command then try increasing the number of retries. Better use the default value. Hope this works fine.

-Archit

AAB
  • 87
  • 1
  • 2
  • 6
  • The issue was that the powershell session was becoming corrupted, and therefore was no longer even executing robocopy at all. – TheCodeKing Mar 21 '12 at 23:02