Customize SetupComplete.cmd and SetupRollback.cmd

Why?  Ever want to run a few tasks after upgrade, or more importantly, ensure a few things happen if the upgrade goes south and rollsback?  Why not hitch a ride on what ConfigMgr is doing natively and add a few things you need.

Supported?  Highly unlikely.  Please test, and please don’t say “Gary did it” as rationalization when someone asks why you decided to do this.

Do you do it?  Heck yes I do, in my lab.  Need to get a little more test results before implementing in Production

How do you use it?  I’m not telling! Oh wait, that’s why I’m blogging.  I modify the SetupRollback.cmd to ensure the machine is pulled out of provisioning mode when it the upgrade rolls back, and to set a registry key for our reporting, and trigger hardware inventory.

Update 2020.09.23 – Added Post about how Windows 10 calls SetupComplete.cmd

More background.
ConfigMgr has two files in the c:\windows\ccm folder that it uses:

  1. SetupCompleteTemplate.cmd
  2. SetupRollbackTemplate.cmd

During the IPU Task Sequence, the Run OS Upgrade Step does many many things (OSDUpgradeOS.exe), like place the machine into provisioning mode, compile the command line to be used with the Windows 10 Setup Engine, and more, including, what we’ve gather here today to talk about, creating the SetupComplete.cmd and SetupRollback.cmd files.

image

These files also live on your server, so if you want to modify the ones in your boot media for whatever reason, you’d do it here: %Program Files%\Microsoft Configuration Manager\OSD\bin\x64
image

Knowing this information, we can then create our own package with those files.
image
I’ve created a readme file with basic info (I tend to forget, which is why I blog and document).  I also created Append text files for each, which contains the additional information I’ve added to each of the two command files.  Why?  So the next time I update CM to the next Current Branch, I can grab the latest SetupCompleteTemplate.cmd and SetupRollbackTemplate.cmd  files and use those.  Perhaps the CM Team updated the scripts with some useful items.  This way, I can just delete the 2 I have, copy the new ones over, and append my additional code to them.

SetupRollbackTemplate.cmd: (Yellow is what I added)
image

Appended Information:

echo %DATE%-%TIME% Exiting setuprollback.cmd (Offical) >> %WINDIR%\setuprollback.log

REM Adding Custom Items HERE
echo %DATE%-%TIME% Starting GARYTOWN Additional Items >> %WINDIR%\setuprollback.log
echo %DATE%-%TIME% Run Command to remove from provisioning mode >> %WINDIR%\setuprollback.log
WMIC /namespace:\\root\ccm path sms_client CALL SetClientProvisioningMode "False" /NOINTERACTIVE
echo %DATE%-%TIME% Removing from provisioning mode Complete >> %WINDIR%\setuprollback.log

REM Setting WaaS Key Registry Key, requires %SMSTS_Build% variable in TS set.
echo %DATE%-%TIME% Setting WaaS_Stage RegKey to IPU_RollBack >> %WINDIR%\setuprollback.log
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\WaaS\%SMSTS_Build%" /V WaaS_Stage /T REG_SZ /D "IPU_RollBack" /F

REM Trigger Hardware Inventory:
echo %DATE%-%TIME% Trigger Hardware Inventory >> %WINDIR%\setuprollback.log
WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000001}" /NOINTERACTIVE

echo %DATE%-%TIME% Exiting setuprollback.cmd after additional custom commands >> %WINDIR%\setuprollback.log
set SCCMClientPath=

In the In Place Upgrade Task Sequence:
image

xcopy *.cmd “%WINDIR%\CCM” /Q /Y /I

I also made a minor change in the SetupComplete.cmd, just so I could confirm this was working without having to reproduce an actual rollback.
image

And as you can see, after the upgrade, the registry key is updated, the log file is also updated.
image

OR… the NO Content Version.  I actual prefer this, as you don’t have to manage a package and keep it updated.
I have 2 steps in the TS, one for each .cmd file.

SetupComplete (just creating a test key, I really don’t have anything I need to do with this, as anything post upgrade I do in the TS)

cmd.exe /c echo REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\WaaS\%SMSTS_Build%" /V Test_CustomBatchFile /T REG_SZ /D "SetupCompleteTemplate" /F >> %WINDIR%\CCM\SetupCompleteTemplate.cmd

SetupFallback, Update WaaS_Status Key, Pull from Provisioning Mode, Trigger HWinv

cmd.exe /c echo REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\WaaS\%SMSTS_Build%" /V WaaS_Stage /T REG_SZ /D "IPU_RollBack" /F >> %WINDIR%\CCM\SetupRollbackTemplate.cmd & cmd.exe /c echo WMIC /namespace:\\root\ccm path sms_client CALL SetClientProvisioningMode "False" /NOINTERACTIVE >> %WINDIR%\CCM\SetupRollbackTemplate.cmd & cmd.exe /c echo WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000001}" /NOINTERACTIVE >> %WINDIR%\CCM\SetupRollbackTemplate.cmd

I hope you find this interesting, if not helpful.
Thanks to @MikeTerrill for showing me these files on the Server, and peeking my curiosity as I search for ways to improve the IPU process, one of which is to reduce the number of machines stuck in provisioning mode after they roll back.
Originally Posted on GARYTOWN.COM

7 thoughts on “Customize SetupComplete.cmd and SetupRollback.cmd”

  1. Hey Gary, good stuff. We do something similar for our IPU as well to handle some BitLocker scenarios and we found we had to manage two instances of the SetupCompleteTemplate.cmd file depending on the version of CM installed on the client. When we moved to the 1710 version of the client from previous versions, we had to accommodate both until all clients were upgraded as there were differences in the file between the two versions. Just something to watch out for but following your process above to simply append to the existing files no matter what version is installed would be easier and thanks for the tip!

    Reply
  2. Hi Gary,

    Thanks so much for the post. It’s funny, up until recently I never even heard of SetupComplete.cmd.

    I am working on upgrading our Win 7 & 10 computers to Win 1803 or 09. Unfortunately we use Symantec encryption. The Symantec supplied scripts are not made for SCCM, or at least, it certainly doesn’t seem like it.

    Symantec has their own SetupComplete.cmd that needs to run. This a great idea adding it to the template. Hope it works. Thanks again!

    Reply
  3. Gary, Hunter,
    We use both SED (versions10.4, 10.3) and SEE (11.2.1, 11.2 and 11.0) and I was able to modify the Symantec scripts to work with SCCM.
    To combine them all I used a script to do a GUID search for the product IDs. If 11.2.1 was installed it would copy the upgrade scripts to the computer.
    I did modify Symantec’s upgrade scripts to allow common variables between both SED and SEE.
    In the task sequence, I run upgrade script before the upgrade OS setup. For the upgrade OS steps, I used the Set Task Sequence Variable = OSDSetupAdditionalUpgradeOptions to add the reflected drivers (which are copied with the upgrade script to the c:\pgptemp folder).
    If you need the scripts or more help shoot me an email.

    Reply

Leave a Comment

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