# Run the real installer on the USB flash (disk 2) elevated, with auto-confirm. $ErrorActionPreference = 'Continue' $dir = 'C:\PF\USBInstaller\test' $out = Join-Path $dir 'flash-run.log' "start: $(Get-Date -Format 'HH:mm:ss') admin=$(([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))" | Set-Content $out -Encoding UTF8 # kill leftovers Get-Process -Name 'test','syn','PF_installer' -ErrorAction SilentlyContinue | ForEach-Object { try { $_.Kill(); "killed $($_.ProcessName) $($_.Id)" | Add-Content $out -Encoding UTF8 } catch {} } Get-CimInstance Win32_Process -Filter "Name='AutoIt3.exe'" | Where-Object { $_.CommandLine -like '*driver-*' } | ForEach-Object { try { Stop-Process -Id $_.ProcessId -Force; "killed AutoIt3 $($_.ProcessId)" | Add-Content $out -Encoding UTF8 } catch {} } Start-Sleep -Seconds 2 # detach leftover test VHD $vhd = 'C:\PF\USBInstaller\test\pf-test.vhdx' $sp = Join-Path $dir 'dp-cleanup.txt' ('select vdisk file="' + $vhd + '"' + "`r`n" + 'detach vdisk noerr' + "`r`n" + 'exit' + "`r`n") | Set-Content $sp -Encoding ASCII & diskpart.exe /s $sp | Out-Null Start-Sleep -Seconds 2 if (Test-Path $vhd) { try { Remove-Item $vhd -Force } catch {} } "leftover vhd present: $(Test-Path $vhd)" | Add-Content $out -Encoding UTF8 & 'C:\Program Files (x86)\AutoIt3\AutoIt3.exe' (Join-Path $dir 'driver-flash.au3') *>> $out "exit: $LASTEXITCODE end: $(Get-Date -Format 'HH:mm:ss')" | Add-Content $out -Encoding UTF8