Hello everbody
I am writing because of an error message in WinPE. I want to create a USB stick which automatically reads the hardware hash and serial number and writes that to a CSV. Like in the following article: https://docs.microsoft.com/en-us/mem/autopilot/add-devices
The WinPE works perfectly so far and I have Powershell mounted in it as well.
First I start Powershell with the following script:
> CMD Script
powershell.exe "Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File E:\mount\Autopilot\Script\Get-AutopilotHash.ps1' -Verb RunAs"
After that this PowerShell script is executed, everything works so far. I have already saved the script from Microsoft "Get-WindowsAutoPilotInfo".
(as info, everything works on a normal computer)
> PowerShellScript:
$SN = (gwmi win32_bios).SerialNumber
$ROOT = get-psdrive |where {$.Root -match ":"} |% {if (Test-Path ($.Root + "AutopilotCSV")){$_.Root}}
$outfilename = "$($SN)_AutoPilotHWID.csv"
Set-Location "$($ROOT)\AutopilotCSV"
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force
. "$($Root)\mount\Program Files\WindowsPowerShell\Scripts\Get-WindowsAutoPilotInfo.ps1" -outputfile $outfilename
Start-Sleep -s 15
Stop-Computer -ComputerName localhost
The script reads the drive letter automatically by looking where a folder named AutoPilotCSV is.
With a Windows To Go on a USB stick is it working
The error messages are these:

Thanks for everyone