Skip to content

Instantly share code, notes, and snippets.

@bender-the-greatest
Last active October 21, 2016 15:13
Show Gist options
  • Save bender-the-greatest/2dce08866ce176426fdc41d021a4c4bf to your computer and use it in GitHub Desktop.
Save bender-the-greatest/2dce08866ce176426fdc41d021a4c4bf to your computer and use it in GitHub Desktop.
Rudimentary implementation of *nix watch command for Powershell
# Rudimentary implementation of *nix watch command for Powershell
# Tested under 2.0 and 5.1
# Example usage:
# watch ls
# watch 'echo "Command with parameters"'
# watch -n 1 'echo "Display this every second"'
# watch -n 1 -command 'echo "Explicit use of the command parameter"'
function watch {
Param(
[Parameter(Mandatory=$true)][string]
$command,
[Parameter(Mandatory=$false)][int]
$n = 2
)
while($true) {
clear
Write-Output (iex $command | Format-Table)
sleep $n
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment