小编Jta*_*44t的帖子

在 Windows PowerShell 中使用计时器

我正在尝试弄清楚如何在 Windows PowerShell 中使用计时器。我希望我的脚本运行命令/任务一段时间,停止任务,然后将结果输出到 txt 文件。这是我到目前为止所拥有的:

$timer = [Diagnostics.Stopwatch]::StartNew()

while ($timer.elapsed.totalseconds -lt 10){

netstat 169.254.219.44 

$timer.stop() | 
Out-File $PSScriptroot\connections.txt

break
}
Run Code Online (Sandbox Code Playgroud)

该脚本所做的就是在终端中运行命令,直到我按 ctrl+c。一旦我按 ctrl+c,它就会停止,然后输出 .txt 文件。但 .txt 文件是空白的。我花了比我应该花的时间更多的时间来试图解决这个问题。我是 Windows PowerShell 的新手,只是闲逛看看我能做什么。该脚本没有真正的目的。这简直让我发疯,我无法弄清楚这一点......

windows powershell scripting timer

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

powershell ×1

scripting ×1

timer ×1

windows ×1