Skip to content

Instantly share code, notes, and snippets.

@jdharmon
Last active July 27, 2020 14:11
Show Gist options
  • Save jdharmon/98669e99f9d31bc6d68810c59a81c3e2 to your computer and use it in GitHub Desktop.
Save jdharmon/98669e99f9d31bc6d68810c59a81c3e2 to your computer and use it in GitHub Desktop.
PowerShell watch
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