Created
September 18, 2015 16:12
-
-
Save mgreenegit/18cd76adff813e06c48a to your computer and use it in GitHub Desktop.
Simple function to render results of a command in real time (or near real time)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function PoshMon { | |
param ( | |
[Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True)] | |
[string]$command, | |
[Int32]$seconds = 300 | |
) | |
Begin { | |
[System.Console]::Clear() | |
[console]::CursorSize = 1 | |
$now = Get-Date | |
$scriptblock = [scriptblock]::Create("$command | format-table") | |
} | |
Process { | |
while ($now.AddSeconds($seconds) -gt (get-date)) { | |
$output = $scriptblock.InvokeReturnAsIs() | |
if ($output -ne $outputLast) { | |
[System.Console]::Clear() | |
$output | |
} | |
$outputLast = $output | |
start-sleep 1 | |
} | |
} | |
End { | |
[console]::CursorSize = 25 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Examples -
Poshmon get-vm
Poshmon 'get-process | sort PM -desc | select -first 8'
Poshmon 'ls c:\projectdir'