Windows 7 Portable Usb < 2024 >
# Validate USB drive letter if (-not ($UsbDriveLetter -match "^[A-Za-z]:$")) Write-Host "Invalid drive letter format. Use like D: or E:" -ForegroundColor Red exit 1
# Diskpart commands to clean, partition, format, set active, assign letter $diskpartCommands = @( "select disk $diskNumber", "clean", "create partition primary", "select partition 1", "active", "format fs=ntfs quick label=WIN7USB", "assign letter=$driveLetter", "exit" ) windows 7 portable usb
# Check if USB drive exists if (-not (Test-Path $drivePath)) Write-Host "Drive $UsbDriveLetter does not exist or is not ready." -ForegroundColor Red exit 1 # Validate USB drive letter if (-not ($UsbDriveLetter
Write-Host "Preparing USB drive (clean, partition, format NTFS, set active)..." -ForegroundColor Yellow Invoke-DiskPart -Commands $diskpartCommands "create partition primary"
param( [Parameter(Mandatory=$true, HelpMessage="Path to Windows 7 ISO file")] [ValidateScript(Test-Path $_ -PathType Leaf)] [string]$IsoPath, [Parameter(Mandatory=$true, HelpMessage="USB drive letter (e.g., D: or E:)")] [ValidatePattern("^[A-Za-z]:$")] [string]$UsbDriveLetter )
$driveLetter = $UsbDriveLetter[0] $drivePath = $UsbDriveLetter + "\"