Skip to content

Instantly share code, notes, and snippets.

@rickykaare
Created April 5, 2022 08:22
Show Gist options
  • Save rickykaare/4e87a3861b6a87a2a157bcd2023366cd to your computer and use it in GitHub Desktop.
Save rickykaare/4e87a3861b6a87a2a157bcd2023366cd to your computer and use it in GitHub Desktop.
Bash watch command for PowerShell
function watch {
$Command = "$args"
$Seconds = 2
if ($args.Length -gt 2 -and $args[0] -eq "-n") {
$Seconds = [int]$args[1]
$Command = $args[2..$args.Length]
}
if ($Command -eq "") {
Write-Host "Usage: watch [-n <sec>] <command>"
return
}
while(1) {
Invoke-Expression "`$result = $Command" 2>&1
Clear-Host
Write-Output "$(Get-Date) : $Command"
Write-Output ""
Write-Output $result
Start-Sleep $Seconds
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment