Unable to Pause or Sleep after Select-Object

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Mica Mica 8 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #33970
    Profile photo of Mica
    Mica
    Participant

    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?

    #33974
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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.

    #33978
    Profile photo of Mica
    Mica
    Participant

    Apparently this is only happening in v5. I posted this on StackOverflow as well:
    http://stackoverflow.com/questions/34835327/unable-to-pause-or-sleep-after-select-object

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.