Correct Logic for Dirve letters and add Dirve Info

to the write-host selection for Disks.
This commit is contained in:
Doctair
2024-07-30 16:11:07 -04:00
parent 047881934a
commit 39b9d06d21
+26 -4
View File
@@ -2927,19 +2927,41 @@ 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-Error "Invalid selection. Exiting."
Write-Warning "Invalid selection. Exiting." | Out-Null
exit 1
}