I'm trying to reset some systems back to Out-of-Box Experience (OOBE) using a PowerShell script. Since the users don't have admin access on their machines, I need this to be user-initiated. The script works well for cleanup and checks, but it fails when attempting to run Sysprep because it can't find sysprep.exe. I'm using this code to check the path for sysprep:
$sysprepPath = "$($env:windir)System32SysprepSysprep.exe"
It always fails at the test-path function, even though I can validate the path manually in PowerShell. Can anyone help with why this is happening or suggest how to fix it?
3 Answers
Have you tried the 64-bit path instead? It would be:
C:Windowssysnativesysprepsysprep.exe
How are you launching your script? If it's the 32-bit version of PowerShell on a 64-bit machine, the System32 folder might be remapped, causing missing items. You should also capture the actual error messages for more insight. You can do that with:
"Script Errors:" | Out-File -FilePath ...
$Error | Out-String | Out-File -FilePath ...
Another tip: Instead of calling cmd.exe, consider using the call operator directly in PowerShell:
$ProgramOutput = & $sysprepPath /reboot /oobe /quiet
If you can get admin access to the device, just use the Administrator command prompt and run:
> systemreset -factoryreset
It will keep the device connected to the network and reset to OOBE mode automatically. It’s a much simpler approach if you don’t need to keep existing applications.
We need to keep the existing applications set up on the device. A factory reset would remove those. We have critical applications installed, and we don’t have their installers, which complicates things as we try to migrate between Intune tenants.
I'm not even getting that far. My script can't find the path.