In some cases, if I try to pause or sleep after a Select-Object command, the pause/sleep occurs before the command.
For example, with
Get-NetAdapter | Select-Object Name,Status
Pause
or
Get-NetAdapter | Select-Object Name,Status | Where-Object {$_ -ne $null}
Pause
the output is:
Press Enter to continue...:
Name Status
---- ------
Wi-Fi Up
Ethernet Disconnected
Whereas with
Get-NetAdapter | Select-Object Name,Status | Format-Table
Pause
the output is:
Name Status
---- ------
Wi-Fi Up
Ethernet Disconnected
Press Enter to continue...:
What’s going on here? Is this a bug or a feature?
I can’t replicate your issue. Are you testing in Powershell ISE? My assumption is you are seeing the script posted to the output window which would appear as though it processed your script?
#cls
$procs = Get-Process
"There are {0} processes running" -f $procs.Count
Pause
"Doing more stuff"
Output:
PS C:\WINDOWS\system32> $procs = Get-Process
"There are {0} processes running" -f $procs.Count
Pause
"Doing more stuff"
There are 98 processes running
Press Enter to continue...:
Doing more stuff
Output with Clear-Host (cls) at the top:
There are 98 processes running
Press Enter to continue...:
Doing more stuff
As I said, the above ran Get-Process, wrote output to the host, paused until I hit enter and then wrote the final host message.