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

0
1
Asked By CuriousCat42 On

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

Answered By CodeGuru88 On

Have you tried the 64-bit path instead? It would be:

C:Windowssysnativesysprepsysprep.exe

Answered By TechSavvy123 On

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.

Answered By SystemAdminPro On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.