我花了大部分时间研究实现这一目标的最佳和最简单的方法,但似乎没有。我找到了一些零碎的东西,但我无法成功地让它们工作。我只是想通过运行 Powershell 脚本向用户显示一条弹出消息。我想让脚本执行以下操作:
1. The popup would give an action for input by the user,
2. The message will tell them their computer will be restarted to complete a Windows 1809 upgrade,
3. The user will click ok and the input, along with the username and machine name will be sent to a log file.
4. The script would have a timer on it that will restart the computer within 30 minutes whether the input is given or not.
下面的代码做我想要的,减去计时器,但不会给用户带来弹出消息。它只是在 Powershell 控制台中给出消息。我怎样才能让它做同样的事情,但在弹出消息中呢?
$HostName = $env:COMPUTERNAME
$PatchLocation = "c:\Temp\"
$LogFile = "responses.log"
$LogPath = $PatchLocation + $LogFile
$date = Get-Date
$response = Invoke-Command -ComputerName $HostName -ScriptBlock{ Read-Host "Your computer will be restarted in 30 minutes. Please save your work. Type 'Agree' If you have saved your work"}
"Response for $HostName is $response - $date"|Out-File -FilePath $LogPath -Append
看看https://jdhitsolutions.com/blog/powershell/2976/powershell-popup/
感谢 Hans Hubert Vogts 提供了弹出消息的代码。它提供了弹出窗口,但是,我需要将脚本输出到日志文件。我修改了代码来做到这一点。它在下面。