Implement "Press Enter to skip"

Viewed 85
$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)

How to implement section with "Press Enter to skip" question instead of $drive -eq "exit"?

1 Answers

Just check if the string is empty:

IF ($drives -eq $drive)
{
    "exists"
}
ELSEIF ([string]::IsNullOrEmpty($drive))
{
    break
}
else
{
    Write-Host "The disk does not exist"
}
Related