Author Posts

September 13, 2014 at 12:40 pm

I see that Microsoft says that you can run Sysprep from the command line, but I can't seem to get it to work on my 2012 r2 server. Not a cmdlet in Powershell and not a recognized command from the command line. I even tried going to the executable, no such luck. The only thing that seem to be getting me close is:

$command = "C:\Windows\System32\Sysprep\Sysprep.exe /generalize /oobe /shutdown /quiet"
Invoke-Expression -command "$command"

but then I get, " If no command-line arguments are provided a graphical user interface is used to select the desired Sysprep operstions."

I am trying to deploy a 3 vm's and script it all out for future use. I have made it through a few big blocks so far.

September 13, 2014 at 1:02 pm

Hi Dan,

The below PowerShell command works for me on 2012 R2.

Start-Process -FilePath C:\Windows\System32\Sysprep\Sysprep.exe -ArgumentList '/generalize /oobe /shutdown /quiet'

Best,
Daniel

September 15, 2014 at 11:32 am

Why are you using Invoke-Expression? What happens when you run:

C:\Windows\System32\Sysprep\Sysprep.exe /generalize /oobe /shutdown /quiet

September 15, 2014 at 1:08 pm

try this

$sysprep = 'C:\Windows\System32\Sysprep\Sysprep.exe'
$arg = '/generalize /oobe /shutdown /quiet'
$sysprep += " $arg"
Invoke-Expression $sysprep

November 15, 2016 at 11:13 am

Hi

When I run the below commands one by one, sysprep is working fine, but when I execute below commands as a file the sysprep is not executing. Sysprep popup window opened and closed for a short time.

$sysprep = 'C:\Windows\System32\Sysprep\Sysprep.exe'
$arg = '/generalize /oobe /shutdown /quiet'
$sysprep += " $arg"
Invoke-Expression $sysprep

Please help to resolve it

Regards,
Mohamed Nazar

November 15, 2016 at 12:27 pm

other possible alternative 🙂

$cmd = 'C:\Windows\System32\Sysprep\Sysprep.exe'
$args = '/generalize','/oobe','/shutdown','/quiet'
& $cmd $args

November 15, 2016 at 1:10 pm

Hi Max, I tried the command but still sysprep is not triggered.

I removed "Quiet" argument and tried and found that the actual issue.

The issue is "a fatal error occured while trying to sysprep the machine"

I just followed the below steps and now sysprep is working fine.

>>>>
Start Search box to open Registry Editor, set the value of GeneralizationState under HKEY_LOCAL_MACHINE\SYSTEM\Setup\Status\SysprepStatus to 7, then run sysprep again.
>>>>
Source: https://social.technet.microsoft.com/Forums/office/en-US/425bd101-8a87-488c-b2e2-9f2f8113a0d9/sysprep-fatal-error-occurred-while-trying-to-sysprep-the-machine?forum=w7itproinstall

Regards,
Mohamed Nazar