I am trying to repeat *nix watch
functionality as provided by johnrizzo1 here.
function Watch {
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='High')]
param (
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[int]$n = 10,
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$command
)
process {
$cmd = [scriptblock]::Create($command);
While($True) {
Clear-Host;
Write-Host "Command: " $command;
$cmd.Invoke();
sleep $n;
}
}
}
Export-ModuleMember -function Watch
watch -n 1 '$PSVersionTable.PSVersion'
The problem is that only 1st run displays headers. After that is looks ugly as headers are being stripped from output:
Command: $PSVersionTable.PSVersion
5 0 10586 117
By the way all other PS solutions to watch
in the link above suffer from the same problem.