What’s missing?
Id Name PSJobTypeName State HasMoreData Location Command
8 Timer.Elapsed NotStarted False …
Script-
$Timer = New-Object Timers.Timer
$objectEventArgs = @{
InputObject = $Timer
EventName = 'Elapsed'
SourceIdentifier = 'Timer.Elapsed'
}
$Timer.Interval = 2000
$Timer.Autoreset = $True
$Timer.Enabled = $True
$n = 0
Write-Output $((Get-Date).ToString() + " Loop Start")
$action = {
if ($n -le 3){
$n = $n +1
Write-Output $n
}else
{
Write-Output $((Get-Date).ToString(), "Loop End")
$Timer.Autoreset = $False
}
}
Register-ObjectEvent @objectEventArgs -Action $action
Unregister-Event -SourceIdentifier 'Timer.Elapsed'
```