Merge pull request #44 from HedgeComp/2408.1

External Disk Selection
This commit is contained in:
rbalsleyMSFT
2024-07-31 10:56:55 -07:00
committed by GitHub
+32 -3
View File
@@ -2927,15 +2927,44 @@ Function Get-USBDrive {
WriteLog 'Found external hard disk media drives'
WriteLog 'Will prompt for user input to select the drive to use to prevent accidental data loss'
WriteLog 'If you do not want to be prompted for this in the future, set -PromptExternalHardDiskMedia to $false'
for ($i = 0; $i -lt $ExternalHardDiskDrives.Count; $i++) {
$ExternalDiskNumber = $ExternalHardDiskDrives[$i].DeviceID.Replace("\\.\PHYSICALDRIVE", "")
$ExternalDisk = Get-Disk -Number $ExternalDiskNumber
if ($VerbosePreference -ne 'Continue'){
Write-Host ("{0}: {1}" -f ($i + 1), $ExternalHardDiskDrives[$i].Model)
# Write-Host ("{0}: {1}" -f ($i + 1), $ExternalHardDiskDrives[$i].Model)
Write-Host ("Drive {0}: {1} SN/{2} PartitionStyle={3} Status={4}" -f ($i + 1), $ExternalDisk.FriendlyName , $ExternalHardDiskDrives[$i].serialnumber, $ExternalDisk.PartitionStyle,$ExternalDisk.OperationalStatus ) -ForegroundColor Green
}
WriteLog ("{0}: {1}" -f ($i + 1), $ExternalHardDiskDrives[$i].Model)
WriteLog ("Drive {0}: {1} SN/{2} PartitionStyle={3} Status={4}" -f ($i + 1), $ExternalDisk.FriendlyName , $ExternalHardDiskDrives[$i].serialnumber, $ExternalDisk.PartitionStyle,$ExternalDisk.OperationalStatus )
}
$inputChoice = Read-Host "Enter the number corresponding to the external hard disk media drive you want to use"
while ($true) {
try {
# Ask the user for input
#$userInput = Read-Host "Please enter a number"
$inputChoice = $(Write-Host "Enter the number corresponding to the external hard disk media drive you want to use: " -ForegroundColor DarkYellow -NoNewline; Read-Host)
# Convert the input to a float
$ISnumber = [float]$inputChoice
# Display the entered number
Write-Host "You selected Disk: $ISnumber"
$selectedIndex = $inputChoice - 1
break
}
catch {
# If the input is not a valid number, display an error message
Write-Host "Invalid input. Please try again."
}
}
if ($selectedIndex -ge 0 -and $selectedIndex -lt $ExternalHardDiskDrives.Count) {
$USBDrives = $ExternalHardDiskDrives[$selectedIndex]
} else {
Write-Warning "Invalid selection. Exiting." | Out-Null
exit 1
}
}
}