How can I run Sysprep via PowerShell if it's not found?

September 3, 2025 3 answers
Asked by CuriousCat42
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?

Answers

SystemAdminPro
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.

CuriousCat42: 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.

Reply to this answer
TechSavvy123
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

ScriptBot99: I'm not even getting that far. My script can't find the path.

Reply to this answer
CodeGuru88
Have you tried the 64-bit path instead? It would be: C:Windowssysnativesysprepsysprep.exe
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions