$time = Get-Date -DisplayHint Time
$addTime = Read-Host -Prompt "How many minutes until computer turns off?"
$addTimeConvert = [timespan]::FromMinutes($addTime)
$addTimeConvertOut = $addTimeConvert.ToString("hh\:mm\:ss")
$newTime = $time + $addTimeConvert
Write-Host $newTime
Write-Host $time
while ($newTime -ne $time){
$time = Get-Date -DisplayHint Time
}
Stop-Computer
我想编写一个脚本来在一段时间后关闭我的电脑,但由于某种原因,即使在同一时间之后,while循环也会继续。
答案 0 :(得分:2)
我可以为(可能的)原始问题提供替代解决方案,而不是回答您提出的问题吗?
$minutes = Read-Host -Prompt "How many minutes until computer turns off?"
Start-Sleep -Seconds (60 * $minutes)
Stop-Computer