Pre-Caching OSD Content

If you want to be able to build machines using OSD at a location which does not have a local distribution point, you can use 2Pint's peer-to-peer functionality to serve the content locally. This can be done by pre-caching a task sequence's content items to existing machines so that new machines being built, can use BranchCache to download the content locally.

To support this, 2Pint Software has provided a task sequence module which which will simplify the process of pre-caching task sequence content. This module is part of the 2Pint OSD Task Sequence Module download, so follow the instructions here, to download and import the modules into Configuration Manager.

Prerequisites

Creating a Package for the OSD Toolkit

The first step in the Pre-caching task sequence module involves copying OSD Toolkit files to the local machine. This can be accomplished in several different ways, but this guidance uses a Configuration Manager package to host specific files which can be found in the OSD Toolkit:

  1. Download the OSD Toolkit from here.

  2. Extract the contents of the OSD Toolkit and in the "Tools" folder, located the folder representing the target architecture (ex. x64), copy the below files to a package source folder: - BCEnabler.exe - BITSACP.exe - BranchCacheTool.exe - HashGen.exe

  3. Create a package in Configuration Manager which references the package source folder. A Program is not required.

  4. Distribute the package to the relevant distribution points.

CM and BranchCache Cache Sizes on Target PCs

When deploying a Pre-cache OSD Content task sequence, consider the free disk space and the configured cache sizes on those machines. When content is downloaded, the CM client will first check to see if enough space is available in the CM client cache and attempt to free up space to make room if there is not enough. Therefore, it is important that the CM client cache size is appropriate to store the task sequence content. More importantly, the size of the BranchCache cache should be sized appropriately to store the task sequence content. Initially, the CM cache and the BC cache should be about the same, but if the content is purged from the CM cache, the BC cache will not be purged.

If the StifleR client is already present on the target PC, the StifleR system should automatically manage the BranchCache cache on all managed clients. In the case where you are not running StifleR, 2Pint has created a script which can be used to configure the BranchCache cache. The script is referred to as the BCTuner Script, and the contents of the script can be found here.

Overview

This task sequence can be customized and deployed as it is simply used to pre-cache OSD task sequence content items to target PCs.

Individual Steps

Copying OSD Toolkit Files to System32

This step is disabled by default because it is dependent on creating a package to host specific OSD Toolkit files. After following the steps referenced above, next to the "Package" field, select the Browse button and specify the package which contains the OSD Toolkit files. Remember to deselect the Disable this step checkbox on the "Options" tab.

Removing items from CCMCache

This step will run the below script which will parse the Configuration Manager Client cache and delete only the content items that are referenced in the Pre-cache OSD Task Sequence.

Removing CCMCache Script

Function Remove-CCMCacheItem {
    [cmdletbinding()]
    param ([string] $ContentID)
    # Connect to resource manager COM object    
    $CMObject = New-Object -ComObject 'UIResource.UIResourceMgr'  
    # Using GetCacheInfo method to return cache properties 
    $CMCacheObjects = $CMObject.GetCacheInfo() 
    # Delete Cache item 
    $CMCacheObjects.GetCacheElements() | Where-Object {$_.ContentID -in $ContentID} | ForEach-Object { 
        $CMCacheObjects.DeleteCacheElementEx($_.CacheElementID,$True)
        Write-Host "Deleted: Name: $($_.ContentID)  Version: $($_.ContentVersion)" -ForegroundColor Red
    }
}


#region clear out duplicates
$CMObject = New-Object -ComObject 'UIResource.UIResourceMgr'
$CMCacheObjects = $CMObject.GetCacheInfo()

#Get Packages with more than one instance
$Packages = $CMCacheObjects.GetCacheElements() | Group-Object -Property ContentID | ? {$_.count -gt 1}

#Go through the Duplicate Package and do magic.
ForEach ($Package in $Packages) 
    {
    $PackageID = $Package.Name
    $PackageCount = ($CMCacheObjects.GetCacheElements() | Where-Object {$_.ContentID -eq "$PackageID"}).Count
    Write-Host "Package: $PackageID has $PackageCount instances" -ForegroundColor Green
    $DuplicateContent = $CMCacheObjects.GetCacheElements() | Where-Object {$_.ContentID -eq "$PackageID"} 
    $ContentVersion = $DuplicateContent.ContentVersion | Sort-Object
    $HighestContentID = $ContentVersion | measure -Maximum
    $NewestContent = $DuplicateContent | Where-Object {$_.ContentVersion -eq $HighestContentID.Maximum}
    write-host "Most Updated Package for $PackageID = $($NewestContent.ContentVersion)" -ForegroundColor Green
    
    $CMCacheObjects.GetCacheElements() | Where-Object {$_.ContentID -eq $PackageID -and $_.ContentVersion -ne $NewestContent.ContentVersion } | ForEach-Object { 
        $CMCacheObjects.DeleteCacheElement($_.CacheElementID)
        Write-Host "Deleted: Name: $($_.ContentID)  Version: $($_.ContentVersion)" -BackgroundColor Red
        }
}  

#endregion

$tsenv = new-object -comobject Microsoft.SMS.TSEnvironment  
$ReferencePkgs = ($tsenv.Value('_SMSTSPkgReferenceList')).split(" ")

foreach ($ReferencePkg in $ReferencePkgs){
    if ($ReferencePkg -ne ""){
        Write-Host "Package $ReferencePkg" -ForegroundColor Green
        Remove-CCMCacheItem -ContentID $ReferencePkg
        Write-Host "----------------------"
    }
}

Setting 2Pint Turbo License

This step is disabled by default because it depends on whether or not you have an 2Pint Turbo license. If you have a Turbo License, enter and confirm your license key in the Value fields. Remember to deselect the Disable this step checkbox on the “Options” tab.

Setting SMSTSAllowTokenAuthURLforACP

This step sets the SMSTSAllowTokenAuthURLForACP task sequence variable to TRUE. More information about this variable can be found here.

Setting 2Pint Software ACP

This step sets a task sequence variable value to the expected path of the 2Pint BITSACP.exe Alternate Content Provider program. This is invoked by the Task Sequence engine to download content.

Pre-caching Package Content

This step is disabled by default because content items from your current OSD task sequence need to be added. This step only allows you to add legacy content items such as boot images, OS images, drivers, and packages. Remember to deselect the Disable this step checkbox on the “Options” tab.

Last updated