Trevor Sullivan's Tech Room

Minding the gap between administration and development

Exporting ConfigMgr Task Sequences

Posted by Trevor Sullivan on 2010/05/13


This article will briefly discuss how to export a ConfigMgr OSD task sequence.

The SMS_TaskSequencePackage class has a lazy property named Sequence which contains the XML for the task sequence. Because this is a lazy property, we must obtain a reference to each WMI instance using its direct path, before we can open the property’s value. Once we have the XML for the task sequence, we can send it off to a text file. The PowerShell code to do that would look like this:

$TsList = Get-WmiObject SMS_TaskSequencePackage -Namespace root\sms\site_lab

ForEach ($Ts in $TsList)
{
$Ts = [wmi]”$($Ts.__PATH)”
Set-Content -Path “$($ts.PackageId).xml” -Value $Ts.Sequence
}

Advertisements

7 Responses to “Exporting ConfigMgr Task Sequences”

  1. […] Exporting ConfigMgr Task Sequences « Trevor Sullivan's Tech Room Filed under: System Center, ConfigMgr 2007 […]

  2. Jeff Imbeault said

    Hey Trevor,

    First, I would like to say thank you for your code, it works really well and it closes the gap we had with our full SCCM automation solution.

    Second, one more question, we compared the “manually” exported TS and the “scripted” exported TS and we seem to be missing a couple XML tags. Here is what’s missing from the scripted TS:

    8VL00008

    16-03-10 version 2.6.2
    0
    ATA Station Task Sequence
    152084496

    2010-03-26T15:38:03

    0

    All of this could be easily scripted into the TS but I wanted to ask you if you have seen this behavior?

    Thank you again for your time

    Jeff

    • Trevor Sullivan said

      Jeff,

      It looks like what’s happening, is the ConfigMgr Provider is stripping the properties of the SMS_TaskSequencePackage WMI class before it writes the XML document out. If you examine the XML document exported from the ConfigMgr console, you’ll see that the root node contains the SMS_TaskSequencePackage properties, and serves as a wrapper for the Sequence property, which contains the SMS_TaskSequence, which is the sequence by itself.

      The reason you’re only getting the task sequence itself, is because the WMI class that we are getting the sequence XML from is the SMS_TaskSequence class, and not the “parent” (I put this in quotes because it’s not an actual parent class) class SMS_TaskSequencePackage, which contains the additional properties exported by the GUI.

      At this point, I’m not sure how to go about exporting the entire SMS_TaskSequencePackage instance, but it’s something to look into 🙂

      Cheers,
      -Trevor

  3. Jeff Imbeault said

    Doh! Looks like the post cleared all the XML tags and only kept the values… Anyway it’s no biggie, like I said, all the remaining tags can easily be added to the TS after the extraction.

    Jeff

  4. Hi Trevor I hope you can shed some light I am trying to programatically adding machines to a sccm collection. I found some code but Iam having trouble with this
    $SmsNewRule = $([wmiclass]$(“\\$($SmsManagementServer)\root\sms\site_$($SmsSiteCode):SMS_CollectionRuleDirect”)).CreateInstance()
    I need to pass credentials

    Martin Zugec from the sccm microsoft forums was kind enough to post this back
    Hi Dene,

    powerscan you use Powershell remoting? Otherwise, you will need to use cmdlet Set-WmiInstance to create new instance (in order to use credentials).

    Martin

    however I am a little lost on how to integrate it into a powershell statement, I assume you set the wmi instance but then what ? , any help will be apreciated.
    cheers Dene

    • Trevor Sullivan said

      Hello Dene,

      Thanks for your inquiry. Another method that you may not have been told of, is to use the WMI COM interfaces to achieve your goal. The ConnectServer() method on the “WbemScripting.SwbemLocator” object allows you to specify alternate credentials, a remote computer, and WMI namespace. This will return a SwbemServices object / interface, whose Get() method you can then use to retrieve a SwbemObject, representing a WMI class. The SwbemObject will have a SpawnInstance_() method, which will allow you to create a new instance of the class (this will also return a new SwbemObject representing the new, in-memory WMI instance). Once you’ve set the properties on the new instance, you can call the Put_() method, which will write the instance back to the WMI provider.

      Cheers,
      Trevor Sullivan

  5. […] Exporting ConfigMgr Task Sequences « Trevor Sullivan's Tech Room […]

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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: