top of page
  • Writer's pictureshishir kushawaha

Calculate Task Sequence Referenced Packages size using PowerShell

Updated: Apr 4, 2023

A task sequence in the context of Operating System deployment is a set of instructions that define the sequence of steps that need to be taken for installing or upgrading Operating System on a device. It involves a collection of packages that contain various components, such as images, drivers, applications, operating systems, software packages, and boot images.

When packages are added to a task sequence, they need to be distributed to distribution points. So, they do consume space on the source directory and the content library of the Distribution Point. For instance, you may need to predict the size of standalone media created by a task sequence, verify the space required for creating USB media, or estimate the space that the task sequence content will occupy in the distribution point. So, in all these cases we need to calculate the size of the packages referenced by the task sequence.


To simplify this process, a script is available that can retrieve information about all the packages associated with a task sequence, sort them by package type, and calculate their total size in gigabytes. The script can handle various types of packages, including applications, software packages, operating systems, boot images, and driver packages. By running this script, administrators can easily determine the size of all packages in a task sequence, allowing them to better manage the distribution of software packages and ensure that the content library of the Distribution Point is not overwhelmed with unnecessary packages.


Initially, the script requires the task sequence package ID as input, following which it searches for all the packages that are referenced in the task sequence.

$taskSequenceResult=Get-CMTaskSequence-TaskSequencePackageId 
$taskSequenceResult|Select-Object Name,BootImageID,Description,PackageId,LastRefreshTime,Sourcedate

Later it will find out the total size of boot image integrated in task sequence as below.

$bootImagePackageID=$taskSequenceResult.bootimageid
$bootImageResult=Get-CMBootImage-id $bootImagePackageID
$bootImageResult|Select-Object Name,PackageId,PackageSize

Post boot image size, it will calculate the size of other packages.

foreach($tPidin$taskSequencePackages)     
{ 
$packageResult=Get-CMPackage-id  $tPid-fast|Select-Object Name,PackageID,PackageSize                 $packageSum=$packageSum+($packageResult.packagesize) 
$pkgref=Get-CMApplication-modelname  $tPid|Select-Object LocalizedDisplayName,PackageID,PackageSize 
$apppkgid=$pkgref.packageid
$ApplicationResult=Get-WmiObject-ComputerName $ProviderMachineName-namespace root\sms\site_$SiteCode-Query "SELECT * from sms_contentpackage where packageid = '$apppkgid'"|Select-Object Name,PackageID,PackageSize 
$applicationSum=$applicationSum+($ApplicationResult.packagesize) 
$OSResult=Get-cmoperatingsystemimage-id $tPid|Select-Object Name,PackageID,PackageSize $osSum=$osSum+($OSResult.packagesize) 
$DriverPackageResult=Get-cmdriverpackage-id $tPid-fast |Select-Object Name,PackageID,PackageSize $driverSum=$driverSum+($DriverPackageResult.packagesize)         [void]$taskSequencePackageResult.add($packageResult)         [void]$taskSequenceApplicationResult.add($applicationResult)         [void]$taskSequenceOSResult.add($OSResult)         [void]$taskSequenceDriverPackageResult.add($DriverPackageResult)     
} 

Finally, it will add all size of different packages and represent the data in .HTML File.

$totalSize=$bootImageSize+$packageSum+$applicationSum+$driverSum+$osSum

Output will be in as below.

You can download the complete script from here.


In summary, the script automates the process of determining the size of packages in a task sequence, simplifying the process of managing software packages in a Distribution Point.


If you have any comments or feedback related to the script or its functionality, you can provide it for further improvement. The purpose of leaving a comment is to suggest any modifications or enhancements that could improve the script's performance or functionality.

539 views0 comments

Recent Posts

See All

Comments


bottom of page