Saya menulis modul PowerShell kecil ini untuk melakukan apa yang Anda cari. Masukkan saja
C:\Users\[username]\Documents\WindowsPowerShell\Modules\Watch
dan lari import-module watch
di PowerShell.
# ---- BEGIN SCRIPT
# Author: John Rizzo
# Created: 06/12/2014
# Last Updated: 06/12/2014
# Website: http://www.johnrizzo.net
function Watch {
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='High')]
param (
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[int]$interval = 10,
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$command
)
process {
$cmd = [scriptblock]::Create($command);
While($True) {
cls;
Write-Host "Command: " $command;
$cmd.Invoke();
sleep $interval;
}
}
}
Export-ModuleMember -function Watch
# --- END SCRIPT