Added Get-USBDrive function to check for presence of USBDrive prior to running if $buildUSBDrive -eq $true

This commit is contained in:
rbalsleyMSFT
2024-02-15 17:11:16 -08:00
parent 3a83d6e642
commit 1c38556e32
+15 -11
View File
@@ -215,7 +215,7 @@ param(
[bool]$CopyUnattend, [bool]$CopyUnattend,
[bool]$RemoveFFU [bool]$RemoveFFU
) )
$version = '2401.1' $version = '2402.1'
#Check if Hyper-V feature is installed (requires only checks the module) #Check if Hyper-V feature is installed (requires only checks the module)
$osInfo = Get-WmiObject -Class Win32_OperatingSystem $osInfo = Get-WmiObject -Class Win32_OperatingSystem
@@ -1084,7 +1084,6 @@ function Remove-FFUVM {
WriteLog "Removing VM: $VMName" WriteLog "Removing VM: $VMName"
Remove-VM -Name $VMName -Force Remove-VM -Name $VMName -Force
WriteLog 'Removal complete' WriteLog 'Removal complete'
$VMPath = $FFUVM.Path
WriteLog "Removing $VMPath" WriteLog "Removing $VMPath"
Remove-Item -Path $VMPath -Force -Recurse Remove-Item -Path $VMPath -Force -Recurse
WriteLog 'Removal complete' WriteLog 'Removal complete'
@@ -1186,15 +1185,7 @@ Function Get-WindowsVersionInfo {
SKU = $SKU SKU = $SKU
} }
} }
Function New-DeploymentUSB { Function Get-USBDrive{
param(
[switch]$CopyFFU
)
WriteLog "CopyFFU is set to $CopyFFU"
$BuildUSBPath = $PSScriptRoot
WriteLog "BuildUSBPath is $BuildUSBPath"
$counter = 0
$USBDrives = (Get-WmiObject -Class Win32_DiskDrive -Filter "MediaType='Removable Media'") $USBDrives = (Get-WmiObject -Class Win32_DiskDrive -Filter "MediaType='Removable Media'")
If ($USBDrives -and ($null -eq $USBDrives.count)) { If ($USBDrives -and ($null -eq $USBDrives.count)) {
$USBDrivesCount = 1 $USBDrivesCount = 1
@@ -1208,6 +1199,15 @@ Function New-DeploymentUSB {
WriteLog "No removable USB drive found." WriteLog "No removable USB drive found."
exit 1 exit 1
} }
return $USBDrives, $USBDrivesCount
}
Function New-DeploymentUSB {
param(
[switch]$CopyFFU
)
WriteLog "CopyFFU is set to $CopyFFU"
$BuildUSBPath = $PSScriptRoot
WriteLog "BuildUSBPath is $BuildUSBPath"
$SelectedFFUFile = $null $SelectedFFUFile = $null
@@ -1239,6 +1239,7 @@ Function New-DeploymentUSB {
Return Return
} }
} }
$counter = 0
foreach ($USBDrive in $USBDrives) { foreach ($USBDrive in $USBDrives) {
$Counter++ $Counter++
@@ -1431,6 +1432,9 @@ if (($LogicalSectorSizeBytes -eq 4096) -and ($installdrivers -eq $true)){
WriteLog 'As a workaround, set -copydrivers $true to copy drivers to the deploy partition drivers folder' WriteLog 'As a workaround, set -copydrivers $true to copy drivers to the deploy partition drivers folder'
WriteLog 'We are investigating this issue and will update the script if/when we have a fix' WriteLog 'We are investigating this issue and will update the script if/when we have a fix'
} }
if ($BuildUSBDrive -eq $true) {
$USBDrives, $USBDrivesCount = Get-USBDrive
}
#Get script variable values #Get script variable values
LogVariableValues LogVariableValues