Last active
July 27, 2020 14:11
-
-
Save jdharmon/98669e99f9d31bc6d68810c59a81c3e2 to your computer and use it in GitHub Desktop.
PowerShell watch
This file contains hidden or 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 Watch-Command { | |
[CmdletBinding()] | |
Param( | |
[Parameter(ValueFromPipeline, Mandatory)] | |
[object] | |
$ScriptBlock, | |
[int] | |
$Seconds = 2 | |
) | |
do { | |
$output = Invoke-Command $ScriptBlock | |
Clear-Host | |
Write-Host ("Every ${Seconds}s {0,$($Host.UI.RawUI.WindowSize.Width-10)}`n" -f [datetime]::Now) | |
$output | |
Start-Sleep $Seconds | |
} while ($true) | |
} | |
Set-Alias watch Watch-Command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment