Hey!
I just ran into a curious problem when doing a fast and simple one-liner. Case: I'm auto rebooting VM's, and watching their uptime tells me if they have rebooted yet. I'm running on Windows Server 2012.
Get-VM | Sort Uptime | Select -Last 10
Works, just the way I like. But I'm lazy, so I decide to use an old trick of mine to repeatedly output to the screen.
while ($true) { Get-VM | Sort Uptime | Select -Last 10; Sleep 1 }But now I get no output at all. Then I tried to see what was going on.
while ($true) { "Are we outputting?" }Works fine. Lets try with Get-VM as well.
while ($true) { Get-VM; "Are we outputting?" }No output again... Curious! Lets test some stuff out
while ($true) { Get-VM; break} # Outputs fine
1..5 | %{ Get-VM } # Takes a long time to run, and outputs all 5 results at once
$result = while ($true) { Get-VM; break} # Command instantly returns. Clearly the Get-VM cmdlet can not have been run yet
$result # Takes a few seconds before we receive the output
It seems like some of the implicit for-eaching stuff is doing something wrong here. But with a little rewrite, I got the script working.
while ($true) { Get-VM | Sort Uptime | Select -Last 10; Sleep 1 }That works.
Anyway, that was a lot of text, but my question is, is this a bug, or is there something going on that I just don't understand? Thanks!