Trevor Sullivan's Tech Room

Minding the gap between administration and development

PowerShell: Report / Check the Size of ConfigMgr Task Sequences

Posted by Trevor Sullivan on 2012/01/10


Introduction

In Microsoft System Center Configuration Manager 2007 operating system deployment (OSD), there is a limitation of 4MB for task sequence XML data. This is discussed in a couple of locations:

The Technet document linked to above says the following:

Extremely large task sequences can exceed the 4-MB limit for the task sequence file size. If this limit is exceeded, an error is generated.

Solution: To check the task sequence file size, export the task sequence to a known location and check the size of the resulting .xml file.

Basically, the Technet troubleshooting article is suggesting that you would need to go into the ConfigMgr console, right-click a task sequence, export it to a XML file, and then pull up the file properties. That’s fine for one-off troubleshooting, but what if you had 1000 task sequences and needed to know how large all of them were? Read on to find out how!

PowerShell Solution

Rather than manually exporting each task sequence to check its size, wouldn’t it be easier to simply report on the size? Thankfully, PowerShell makes doing this quite easy. Basically, all we’re going to do in this script is:

  1. Retrieve a list of all task sequence packages (SMS_TaskSequencePackage)
  2. Retrieve a reference to each task sequence by its WMI path (required for lazy property value retrieval)
  3. Add a custom, dynamic “Script Property” to the task sequence object
    1. This dynamic property tells us how many bytes (size) the task sequence XML is made up of
  4. Filter for a couple interesting properties to report on

There are a couple other tricks going on in the script, for example the .NET string formatting to truncate the decimal spaces of the Size (KB) property.

<#
    .Synopsis
    Checks to see what the size of the ConfigMgr task sequence XML is. It must be less than 4 MB.

    .Author
    Trevor Sullivan (pcgeek86@gmail.com)

    .Notes
    Use at your own risk
#>

function Check-SccmTaskSequenceSize {
    param (
        [Parameter(Mandatory = $true)] [string] $SccmServer
        , [Parameter(Mandatory = $true)] [string] $SiteCode
        , [string] $TaskSequenceId
    )

    $TaskSequenceList = Get-WmiObject `
        -ComputerName $SccmServer `
        -Namespace root\sms\site_000 `
        -Class SMS_TaskSequencePackage;

    # Iterate over task sequence objects
    foreach ($TaskSequence in $TaskSequenceList) {
        # Obtain reference to "raw" WMI object using its WMI path (so we get lazy properties)
        $TaskSequence = [wmi]($TaskSequence.__PATH);
        # Add a PowerShell script property to determine the size of the task sequence
        Add-Member `
            -InputObject $TaskSequence `
            -MemberType ScriptProperty `
            -Name Size `
            -Value { ([byte[]][char[]]$this.Sequence).Count };

        # Write-Host -Object $TaskSequence.Size;

        # Write the updated task sequence object to the pipeline
        Write-Output -InputObject $TaskSequence;
    };
};

# USE CASE 1: Get sorted list of all task sequences
# 1. Get ConfigMgr task sequences
# 2. Select Name and Size (KB) properties
Check-SccmTaskSequenceSize `
    -SccmServer sccm01 `
    -SiteCode lab `
    | `
    Select-Object `
        -Property Name, @{ Name = 'Size (KB)'; Expression = {
            [Double]('{0:0.00}' -f ($_.Size/1KB))
        } }

break;

# USE CASE 2: Get sorted (by size) list of all task sequences
# 1. Get ConfigMgr task sequences
# 2. Select Name and Size (KB) properties
# 3. Sort by Size (KB) ascending
Check-SccmTaskSequenceSize `
    -SccmServer sccm01 `
    -SiteCode lab `
    | `
    Select-Object `
        -Property Name, @{ Name = 'Size (KB)'; Expression = {
            [Double]('{0:0.00}' -f ($_.Size/1KB))
        } } `
    | Sort-Object -Property 'Size (KB)';

# USE CASE 3: Get sorted (by name) list of all task sequences
# 1. Get ConfigMgr task sequences
# 2. Select Name and Size (KB) properties
# 3. Sort by Name ascending
Check-SccmTaskSequenceSize `
    -SccmServer sccm01 `
    -SiteCode lab `
    | `
    Select-Object `
        -Property Name, @{ Name = 'Size (KB)'; Expression = {
            [Double]('{0:0.00}' -f ($_.Size/1KB))
        } } `
    | Sort-Object -Property Name;

This should make it much easier for you to determine which task sequences are approaching the limit! There are several examples included which show how to tweak the output Check-SccmTaskSequenceSize PowerShell function in practically useful ways:

  1. List all task sequence packages, with Name and Size properties
  2. List all task sequence packages, with Name and Size properties (sorted by Size)
  3. List all task sequence packages, with Name and Size properties (sorted by Name)

You will need to specify your SccmServer and SiteCode parameters yourself on the Check-SccmTaskSequenceSize function.

Let me know if you have any questions at pcgeek86@gmail.com or in the comments.

Advertisements

2 Responses to “PowerShell: Report / Check the Size of ConfigMgr Task Sequences”

  1. […] Read the full post here. Posted: Jan 10 2012, 01:43 PM by cnackers | with no comments Filed under: SCCM, Powershell, Task Sequence, ConfigMgr […]

  2. PowerShell: Report / Check the Size of ConfigMgr Task Sequences…

    Trevor Sullivan has created a nice post on checking the size ……

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: