首页 > 解决方案 > powershell中的计时器事件在远程会话中不起作用

问题描述

我有一个从机器 A 到 B 的远程 PowerShell 会话。要求是在 B 内部进行连续检查。在特定条件下,我必须执行某些操作并停止计时器。为此,我创建了一个计时器功能。但是那个定时器功能没有启动。

我写的代码是:

$timer = new-object timers.timer 

$action = {
    write-host "inside loop.."
    # Condition to check comes here.
}

$timer.Enabled = $true 
$timer.Interval = 3000 #3 seconds 

Register-ObjectEvent -InputObject $timer -EventName elapsed –SourceIdentifier thetimer -Action $action 

$timer.start()

我希望输出是

内循环..内循环..内循环..

但实际输出是:

Id----------------1
名称----------
定时器 PSJobTypeName---------
状态---- ---------NotStarted
HasMoreData--------假

标签: powershell

解决方案


推荐阅读