Search code examples
powershelloutput-bufferingpowershell-isepowershell-4.0

One line of output at a time


I want to get one line of output at a time while running this command.

Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx | Format-Table -Property Title, pubDate

So I want to get one line of output and then press Enter or Any key to get the next line of out or press Ctrl+C to break the command.

I couldn't achieve it with $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')


Solution

  • I'ld do something like this:

     $A = Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx | select -Property Title, pubDate
    FOR ( $I = 0; $I -le $A.Length; $I++ )
    {
        $A[$i] 
        .\pause ""
    }
    

    or one liner ( look comment )

    Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx |
           select -Property Title, pubDate | 
               % { $_ ; .\pause }
    

    My pause.ps1* file script:

    param([string]$Message="Press any key to continue...")
    Write-Host -NoNewLine $Message
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    Write-Host ""
    

    *this doesn't work in ISE.