Adding Roles and Features in SCCM Task Sequence

Should be simple. And I have done it before and it was, dead simple. This post kinda overlaps with running powershell scripts, batch files, and command lines from Task Sequence, and the example here is Roles and Features.

Sticking with deploying Server 2008 R2 for simplicity, I want to add Roles and Features after the OS is installed: .NET Framework, and RDS, for XenApp Servers.

Previously, you could use ServerManagerCmd.exe for this, so when deploying 2008 or earlier then you need to modify accordingly. ServerManagerCmd is deprecated in R2 so you need to use Powershell, and the servermanager module.

First thing is to set the exec policy: i use a command-line step in the Task Sequence:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -command “&{Set-ExecutionPolicy Unrestricted -Force}”

But you can also use a command line with Reg:

reg add HKLM\Software\Microsoft\Powershell\1\ShellIds\Microsoft.Powershell /v ExecutionPolicy /t REG_SZ /d Unrestricted /f

Of course you need to run from command line for the posh variant because you can’t use a powershell script to set the execution policy when the policy already restricts scripts from running – a chicken and egg analogy. Incidentally, the egg came first. A reptile egg presumably, but it hatched into a genetic mutation which in turn laid a mutant egg and this process eventually led to to the chicken being hatched from a non-chicken egg. So perhaps the chicken did come first then if you mean which came first, chicken or chicken’s egg? Otherwise it’s egg. Maybe better to think how you might get your car keys out of your locked car. That’s a simpler conundrum.

Anyway, onward. Another command-line:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -command “&{Import-Module -Name C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ServerManager\servermanager.psd1;Add-WindowsFeature AS-NET-Framework -includeAllSubFeature}”

The option with this last command-line is that you can put it in a script with a whole host of other post install tasks or changes, package it and call from the task sequence. Obviously your script only needs the part in the “{}”. Interestingly I was getting errors last time with paths, hence the full paths to the exe and psd1, but it does work without these so long as working dir etc is correct.

So that’s a pretty easy way to install a role or feature. But you could also use the MDT integration with SCCM to create a MDT Task Sequence.

For MDT you need to configure the MDT integration, and create an MDT Tools Package: when you create a new MDT TS you can create the Tools package in the wizard.

Be careful though, for some reason if you use a standard SCCM TS and add MDT steps they don’t always work. It’s easier to create a whole MDT TS and modify it accordingly, particularly for Roles and Features. For installing Language Packs, you can use a standard SCCM TS and add the Use MDT Toolkit step, then Language Pack Offline step and it works fine. Not so with Roles/Features. Funny.

Err on the side of caution I say, create the MDT TS and remove the extraneous steps and groups. It’ll save you time. Time enough to figure out how to get your keys…

Advertisement

7 thoughts on “Adding Roles and Features in SCCM Task Sequence

  1. Ox March 25, 2013 / 3:25 pm

    Hi Andrew, did you perform this with SCCM 2007 or 2012? I have been trying to automate the installation of Roles and Features with a SCCM 2007 TS and I have followed your steps exactly; however, I am still getting an 80070002 error in my smsts.

    • andrewdcraig March 25, 2013 / 5:05 pm

      hello Ox,
      are you using the powershell or mdt method? this was originally on 2007.
      regards

      • Ox March 25, 2013 / 6:21 pm

        PowerShell. No MDT integration. I noticed this in my smsts log..

        The term ‘Add-WindowsFeature’ is not recognized as the name of a cmdlet, functi InstallSoftware 3/25/2013 4:47:08 PM 1904 (0x0770)
        on, script file, or operable program. Check the spelling of the name, or if a p InstallSoftware 3/25/2013 4:47:08 PM 1904 (0x0770)
        ath was included, verify that the path is correct and try again. InstallSoftware 3/25/2013 4:47:08 PM 1904 (0x0770)
        At line:1 char:125 InstallSoftware 3/25/2013 4:47:08 PM 1904 (0x0770)
        + InstallSoftware 3/25/2013 4:47:08 PM 1904 (0x0770)
        + CategoryInfo : ObjectNotFound: (Add-WindowsFeature:String) [], InstallSoftware 3/25/2013 4:47:08 PM 1904 (0x0770)
        CommandNotFoundException InstallSoftware 3/25/2013 4:47:08 PM 1904 (0x0770)
        + FullyQualifiedErrorId : CommandNotFoundException InstallSoftware 3/25/2013 4:47:08 PM 1904 (0x0770)

      • andrewdcraig March 25, 2013 / 8:05 pm

        Hi, what server operating system are you installing? And did you try with the full path? Looks like it hasn’t loaded the server manager module…

      • Ox March 25, 2013 / 8:09 pm

        I did try it with the full path. That’s what has me puzzled. I am not sure why it says the module isn’t there because of course, it is.

      • andrewdcraig March 25, 2013 / 8:12 pm

        The command is one-line, despite word-wrapping on the blog… Is that possible?

      • andrewdcraig March 25, 2013 / 8:08 pm

        Oh, check for word-wrapping.. The command is all one line but sometimes looks like there is a line break at “c:\windows…”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s