gpt4 book ai didi

powershell - 实现 “Press Enter to skip”

转载 作者:行者123 更新时间:2023-12-02 23:35:35 24 4
gpt4 key购买 nike

$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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com