powershell - 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--------假
解决方案
推荐阅读
- html - 如何在多个相互覆盖的 HTML 元素上触发鼠标单击事件?
- c# - 选择行时gridview中按钮的可见性ASP.net c#
- javascript - nodeJS:TypeError:将循环结构转换为 JSON
- python - 使用 pandas pd.concat 后丢失的列
- node.js - 如何保存用户然后保存上传图片
- regex - 正则表达式与转义括号不匹配
- encryption - 如何使用 BCryptPasswordEncoder 解码密码?
- python - 在 Python 3.7 中,来自 sys.settrace 的“操作码”事件是否提供有关字节码本身的任何信息?
- python - 我不断收到错误“NameError: name 'labelAns' is not defined”,
- vue.js - 无法从商店获取计算状态的数据 - Vue