I'm setting up Windows Deployment Services (WDS) for Windows Server 2012 unattended deployments using the default boot.wim file found on the install media. I have a PowerShell script that performs automated customisations for our site. I want this script to be run during the specialize pass, so I don't have to mess about with auto logins and to be able to save myself a reboot during provisioning. The script doesn't appear to run and the logs only give an unhelpful error code.

Here is the relevant part of my unattend file:

    <settings pass="specialize">
        <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <RunSynchronousCommand wcm:action="add">
                    <Path>"c:\windows\system32\windowspowershell\v1.0\powershell.exe" -executionpolicy unrestricted -command "\\<REMOTESERVER>\reminst\customize\specialize.ps1"</Path>

In response to request from kce. Here's the script itself:

write-host "Executing customisation script."
write-host "enabling powershell script execution"
Set-ExecutionPolicy Unrestricted

write-host "Bringing non-system disks online..."
Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False
Set-Disk -Number 1 -IsReadOnly $False
Set-Disk -Number 2 -IsReadOnly $False

write-host "Setting up NTP..."
W32tm /register
start-service w32time
w32tm /config /manualpeerlist:uk.pool.ntp.org
restart-service w32time
Set-Service W32Time -StartupType Automatic
sc triggerinfo w32time start/networkon stop/networkoff
sc config W32Time start=auto

write-host "Determining system RAM and setting pagefile..."
$RAM = Get-WmiObject -Class Win32_OperatingSystem | Select TotalVisibleMemorySize
$RAM = ($RAM.TotalVisibleMemorySize / 1kb).tostring("F00")
write-host "disable automanage"
wmic computersystem set AutomaticManagedPagefile=False
Write-Host "removing old pagefile"
wmic pagefileset delete
write-host "creating new pagefile on E:\"
wmic pagefileset create name=“e:\pagefile.sys”
write-host "set size"
$PageFile = Get-WmiObject -Class Win32_PageFileSetting
$PageFile.InitialSize = $RAM
$PageFile.MaximumSize = $RAM

write-host "Disabling Windows Firewall..."
netsh advfirewall set allprofiles state off

write-host "Enabling powershell remoting..."
Enable-PSRemoting -Force

write-host "Sorting out remote management trusted hosts..."
winrm s winrm/config/client '@{TrustedHosts="*"}'

write-host "Disabling Windows error reporting..."

write-host "Installing VMware Tools..."
c:\vmware-tools.exe /S /v"/qn"
  • Edited for the proper powershell command to get around the executionpolicy thing
    – snoweagle
    Feb 14, 2013 at 16:12
  • What is the unhelpful error code in your logs? Also, what's the script itself doing?
    – MDMarra
    Feb 14, 2013 at 16:17
  • the "error I'm getting" is: executing synchronous user provided commands STATUS: SUCCESS (0x00000001)
    – snoweagle
    Feb 14, 2013 at 16:35
  • 1
    I'd echo the output of whoami while that script is being run. Even though you provide credentials, I get the sneaking suspicion it's running as SYSTEM. Have you tested to see if your script works as SYSTEM using something like psexec -s c:\windows\system32\windowspowershell\v1.0\powershell.exe" -executionpolicy unrestricted -command "\\<REMOTESERVER>\reminst\customize\specialize.ps1"
    – MDMarra
    Feb 14, 2013 at 16:44
  • 1
    I've run it in OOBE with autologon and the last command being shutdown /r /t 10. I've never tried it in Specialize, since some things in Windows 7 would balk at being installed during that phase, like SQL Server.
    – MDMarra
    Feb 14, 2013 at 16:59

1 Answer 1


From what I'm reading, an uncaught throw results in the exit code being one. Also, you're passing in the script path through the -command switch, when it should be passed through the -file switch; see the reference. -command will treat your string as a command and since it's a file path, it will throw one of those same red-letter exceptions we love in the PowerShell window, and voila! Exit code 1 since the exception is uncaught. All that is speculation of course, unless

"powershell.exe" -executionpolicy bypass -noprofile -file "\\<REMOTESERVER>\reminst\customize\specialize.ps1"

actually works, assuming the account it's running under has permissions to the fileshare. To avoid those permission issues you could just paste the code in the answer file between {} and then you would use the -command option,

"powershell.exe" -executionpolicy bypass -noprofile -command {...}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.