Last active
September 1, 2021 20:47
-
-
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.
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
# 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