$drives = (Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume).DriveLetter
do
{
$drive = Read-Host -Prompt "Type the drive letter"
IF ($drives -eq $drive)
{
"exists"
}
IF ($drive -eq "exit")
{
break
}
else
{
Write-Host "The disk does not exist"
}
}
until ($drives -eq $drive)
如何用“按Enter跳过”问题而不是$ drive -eq“退出”来实现部分?
最佳答案
只需检查字符串是否为空:
IF ($drives -eq $drive)
{
"exists"
}
ELSEIF ([string]::IsNullOrEmpty($drive))
{
break
}
else
{
Write-Host "The disk does not exist"
}
关于powershell - 实现 “Press Enter to skip”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56789226/