Skip to content

Instantly share code, notes, and snippets.

@mgreenegit
Created September 18, 2015 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgreenegit/18cd76adff813e06c48a to your computer and use it in GitHub Desktop.
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)
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
}
}
@mgreenegit
Copy link
Author

Examples -
Poshmon get-vm
Poshmon 'get-process | sort PM -desc | select -first 8'
Poshmon 'ls c:\projectdir'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment