【发布时间】:2020-12-03 08:15:04
【问题描述】:
我是 PS 的初学者,但我试图让我的生活更轻松,我创建了一个按钮来重新启动计算机,然后告诉我它何时在线。我一直在尝试 -Wait 参数,但会抛出错误。如果有人能指出我正确的方向,那就太好了。
Restart_Computer_Click ={
$again = 1
While($again -ne 'N'){
$ComputerName = Read-Host "ComputerName"
#output online
if (Test-connection $ComputerName -quiet -count 2){
write-host -foregroundcolor green "$ComputerName is online"
Restart-computer -computername $ComputerName -Force -Confirm
}
else{
#output -offline
write-host -foregroundcolor red "$ComputerName is offline"
}
$again = read-host "Reboot Again? y/n"
$again.toUpper() | out-null
}
}
【问题讨论】:
-
我不确定您要的是什么。您想知道如何在脚本中暂停吗?如果是这样,您可以使用
Start-Sleep -
基本上我正在寻找单击我的按钮i 它会询问计算机名称它提示我从 -confirm 参数中询问我是否确定然后它会跟踪计算机直到它重新联机
-
有什么错误?
-
我今天回复了类似的东西。在这里查看:stackoverflow.com/questions/63389087/… 这能回答你的问题吗?
-
如果您想制作一个按钮,您将不得不编写一个小的 Windows 窗体或 Windows Presentation Foundation 对话框。那里有很多关于如何做到这一点的东西,只需谷歌它。至于
Restart-Computer命令你可以使用-For和-Wait来等待特定服务上线,你也可以添加-TimeOut。这一切都取决于,但你可能不需要睡眠等待循环等......
标签: powershell scripting powershell-3.0