Unable to Pause or Sleep after Select-Object

This topic contains 2 replies, has 2 voices, and was last updated by  Mica 1 year, 10 months ago.

  • Author
    Posts
  • #33970

    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

    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

    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

You must be logged in to reply to this topic.