Building a SCCM Lab with 1606

One of the things I do pretty often is rebuild my lab. I do this with a series of scripts I posted to GitHub called the EphingLab. I decided to post about my SCCM 1511 install script that not only installs SCCM, but also updates it to the latest version (1606 currently).

If you’d just like to get the script and try it out yourselves, the link to SCCM script is here.

I’m not going to cover the entire script (it’s over 450 lines) but will cover the parts that aren’t part of your standard build scripts.

The first problem when creating this script that I had to solve was an issue of reboots. I can’t very well go and install all the prereqs, SQL, the ADK, and WSUS without needing at least one reboot between them. To solve that issue I came up with a function called AutoLogon and use it with this template:

The idea is I want to keep running this script, but only want certain sections of code to run depending on the number of times it’s run. So I put a property in the registry with the number of times the script ran, and then keep incrementing the property by 1 every time the script runs.

I then go and install all the required Windows features, and then I set up the System Management container in AD. This code both creates the container and then sets the correct permissions so you don’t have to worry about that:

Then, I reboot and install the ADK, SQL, extend the schema, and install & configure WSUS. Here’s how I’m installing and configuring WSUS:

I then restart the computer and get onto installing SCCM! After installing SCCM, I enable fast ring updates. A few weeks ago, the ConfigMgr team posted a script to TechNet gallery which enables early update ring for SCCM to get production updates before everyone else. I took this script, modified it to work in my lab, and then put the code in my lab build script!

I then reboot the computer and open up the SCCM console. I use send keys to then open up the PowerShell command prompt through the console and send A (for always) to the scripts. There is a onetime setup piece to the PowerShell cmdlets that imports a certificate. I’m hunting down the code to do this without send keys, but for now this code works!

I then reboot (to make it see the certificate and the SCCM PS drive) and start configuring the site! I have code here to install all the standard roles I use, set up boundaries, and set up discover methods. This way the site’s ready and I don’t have these manual steps!

Lastly, I wait for the site to see an update from Microsoft, and run the first one it sees! Right now, that’s 1606. In the future, the newest update might not be the first, so I’ll need to figure out a better long-term solution for this lab build script. But, for now, this works to start installing 1606!

And then that’s it! The script is still a work in progress. I realized I didn’t create a client push account during this process, so I’ll come back and add that to my configuration steps. But this should be a good starting point if you want to not only install SCCM, but configure it automatically whenever you rebuild your lab!

Edit 8/10/2016

I added ‘AND State = 262146’ to the end of the query in the code to start the 1606 update. Thank you to Richard Xia in the comments for pointing out the script needed to wait for the update to go to that state before initiating the install.

Bookmark the permalink.


  1. The last script will get customers into a very bad state.
    Query = “Select * from SMS_CM_UpdatePackages where Name like ‘$($LatestUpdateName)'”
    Per download flowchart,; the STATE of the ConfigMgr update goes to a few different stage, the script has to make sure the State is AVAILABLE (262146). which means the content has been successfully downloaded.
    Without the content downloaded, running the script could cause the payload to be bad/incomplete


      It worked the few times I tried it without the state piece, but I’ll modify the query to add the STATE condition and then test it.

      Is there any documentation on that WMI class? I spent a few hours trying to map state codes to English before I gave up on that.

  2. Nice.
    Fir the cert import part…look in this post, I think the function mentioned there does exactly that ,
    Best regards

Leave a Reply

Your email address will not be published. Required fields are marked *