我想编写一个脚本,提示用户输入一个以分钟为单位的时间来启动关机计时器。我让它工作但没有输入验证。这就是我所拥有的。
DO{
try{
$numOk= $true
[int] $minutes= Read-Host "Enter the amount in minutes until a shut down (0 to cancel)"
#$minutes= [int]$minutes
}
catch{
#if($minutes -isnot [int]){}
$numOk= $false
Write-Host "Input is not an integer!!!!!"
}
} while ($numOk = $false)
[int] $seconds= $minutes*60
if($seconds -eq 0){
shutdown -a
}
else{
shutdown -s -t $seconds
}
Run Code Online (Sandbox Code Playgroud)
当我输入一个字母时,我得到了一个非常奇怪的值。
PS C:\Users\USER\Desktop\shut down> .\shutdownTimer.ps1
Enter the amount in minutes until a shut down (0 to cancel): a
Input is not an integer!!!!!
Cannot …Run Code Online (Sandbox Code Playgroud) powershell ×1