This topic contains 6 replies, has 6 voices, and was last updated by
September 13, 2014 at 12:40 pm #18784ParticipantPoints: 24Rank: Member
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 #18785ModeratorPoints: 24Rank: Member
The below PowerShell command works for me on 2012 R2.
Start-Process -FilePath C:\Windows\System32\Sysprep\Sysprep.exe -ArgumentList '/generalize /oobe /shutdown /quiet'
September 15, 2014 at 11:32 am #18816ParticipantPoints: 55Rank: Member
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 #18818ParticipantPoints: 0Rank: Member
$sysprep = 'C:\Windows\System32\Sysprep\Sysprep.exe' $arg = '/generalize /oobe /shutdown /quiet' $sysprep += " $arg" Invoke-Expression $sysprep
November 15, 2016 at 11:13 am #57698ParticipantPoints: 0Rank: Member
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"
Please help to resolve it
November 15, 2016 at 12:27 pm #57712ParticipantPoints: 0Rank: Member
other possible alternative 🙂
$cmd = 'C:\Windows\System32\Sysprep\Sysprep.exe' $args = '/generalize','/oobe','/shutdown','/quiet' & $cmd $args
November 15, 2016 at 1:10 pm #57716ParticipantPoints: 0Rank: Member
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.
The topic ‘Sysprep from PowerShell, is it possible?’ is closed to new replies.