Skip to content

Instantly share code, notes, and snippets.

@ghoomfrog
Last active September 1, 2021 20:47
Show Gist options
  • Save ghoomfrog/f65b9cc536022d8a25837d4d995658f8 to your computer and use it in GitHub Desktop.
Save ghoomfrog/f65b9cc536022d8a25837d4d995658f8 to your computer and use it in GitHub Desktop.
Keep invoking an expression between an interval. Similarly to Unix's watch command.
# Put this in 'C:\Program Files\WindowsPowerShell\Repeat\Repeat.psm1'.
function Repeat {
param(
$expression,
$interval = 2,
[switch]$clearScreen = $False
)
if ($expression) {
while (1) {
if ($clearScreen) {cls}
Invoke-Expression $expression
sleep $interval
}
} else {
Write-Host -ForegroundColor red 'Repeat: No expression given.'
}
}
Export-ModuleMember -Function Repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment