Just a teensy update - tweaked the script a little, and tested on SCCM CB - 1511
In regular Software Deployment items such as packages and Applications you have a Checkbox on the 'Distribution Point' tab like this:
Checking this box means that BranchCache can be used to share content with other clients on the subnet.
In Task Sequences however, this checkbox isn't there, so we've knocked up a little script that can be used with a Status Filter Rule (or standalone if you prefer) to set the parameter that's required. This will enable you Task Sequence content to be downloaded in a BranchCache stylee.
The setting for BranchCache sharing isn't actually documented, but it's really just one of these AdvertFlag properties - more of which are documented here - http://msdn.microsoft.com/en-gb/library/cc146108.aspx
What are these tricky 'Flag' fellows I hear you ask? Well it's a bit boring and probably warrants a blog of it's own. So I 'll just give the quick (half-pint) version.
Flags are either ON or OFF - so perfect for checkboxes. In the SMS_Advertisement WMI Class, there's a property called AdvertFlags. You can examine this in WMI Explorer - ROOT\SMS\SMS_Advertisement
Find a Task Sequence - and look at the AdvertFlags property. In my example below it's set to 42598400
To cut a long and tedious explanation short - run this bit of SQL and you'll see what I mean - it does the BitWise work for you to turn this decimal value into Flags..
SELECT
ad.AdvertisementID,
ad.AdvertisementName,
AdvertFlags,
(AdvertFlags & 0x00000020)/0x00000020 AS AD_IMMEDIATE,
(AdvertFlags & 0x00000100)/0x00000100 AS AD_ONSYSTEMSTARTUP,
(AdvertFlags & 0x00000200)/0x00000200 AS AD_ONUSERLOGON,
(AdvertFlags & 0x00000400)/0x00000400 AS AD_ONUSERLOGOFF,
(AdvertFlags & 0x00008000)/0x00008000 AS AD_WINDOWS_CE,
(AdvertFlags & 0x00010000)/0x00010000 AS AD_BRANCHCACHE_ENABLE,
(AdvertFlags & 0x00020000)/0x00020000 AS AD_DONOT_FALLBACK,
(AdvertFlags & 0x00040000)/0x00040000 AS AD_ENABLE_TS_FROM_CD_AND_PXE,
(AdvertFlags & 0x00100000)/0x00100000 AS AD_OVERRIDE_SERVICE_WINDOWS,
(AdvertFlags & 0x00200000)/0x00200000 AS AD_REBOOT_OUTSIDE_OF_SERVICE_WINDOWS,
(AdvertFlags & 0x00400000)/0x00400000 AS AD_WAKE_ON_LAN_ENABLED,
(AdvertFlags & 0x00800000)/0x00800000 AS AD_SHOW_PROGRESS,
(AdvertFlags & 0x02000000)/0x02000000 AS AD_NO_DISPLAY,
(AdvertFlags & 0x04000000)/0x04000000 AS AD_ONSLOWNET
FROM dbo.v_Advertisement ad
As you can see above - I've added in BIT 16 - (AdvertFlags & 0x00010000)/0x00010000 AS AD_BRANCHCACHE_ENABLE - as this is the one we want to check/set.
So on to the Main Course - here's the script that you can use to flip BIT 16 to ON if it is OFF. In it, we use Powershell BitWise operator, which are really powerful (and simple to use).
We use the -bor operator, so that each binary value is compared, and in each position if there is a one present in either number then a one is returned for that position.
As we are only presenting a value representing one flag (65536 in this case) - the result is that the AD_BRANCHCACHE_ENABLE flag is set and all others are left in place.
Here's the code - short but sweet!
# .Synopsis sets the checkbox/bit within an advert to 'Allow Clients to share content etc..'
# In a TS this checkbox is not available so this script can BranchCache-Enable your
# Task Sequences. Use in a status filter rule to automate the process if you like!
# Could be used to set any flag - just change the $Bit value..
# .Notes Author : Phil Wilcock - [email protected]
# Blog : http://twopint.wpengine.com/blog
# Date : 2016/24/02
# Version : 1.1 - Updated for SCCM CB - 1511
# .Usage - setadvertflags.ps1 $siteserver $sitecode $deploymentID
# USE AT YOUR OWN RISK #
$siteserver = $args[fusion_builder_container hundred_percent="yes" overflow="visible"][fusion_builder_row][fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="no" center_content="no" min_height="none"][0]
$siteCode = $args[1]
$advertID = $args[2]
$BitValue = 65536 #65536 is the 'BranchCache Enable' flag (undocumented) - find others here - http://msdn.microsoft.com/en-gb/library/cc146108.aspx
$LogPath = $env:SMS_LOG_PATH # places the logfile in with all the other SCCM logs on the server
# let's have a bit of logging eh?
function write-log ($string)
{
$string + " " + (get-date) `
| Out-File $LogPath\SetBranchCacheFlags.log -Append
}
# get the advert info from wmi and check the PackageType to test if it's a Task Sequence - if it isn't we can log it
if ((gwmi -computername $siteserver -ns "root\SMS\Site_$sitecode" -class SMS_AdvertisementInfo | WHERE {$_.AdvertisementID -eq $advertID -and $_.PackageType -eq 4}
) -eq $null) {write-log ("This ain't no Task Sequence deployment - outta here!"); Exit 99}
#ok carry on
$adv = gwmi -computername $siteserver -ns "root\SMS\Site_$sitecode" -class SMS_Advertisement | WHERE {$_.AdvertisementID -eq $advertID}
$adv2 = [wmi] $adv.__Path
# set the bit
$adv2.AdvertFlags = $adv2.AdvertFlags -bor $BitValue
#save it back to WMI
$adv2.Put()
#update the log so that we can trace each time the rule runs
write-log ("2PS Filter Rule Set the BranchCache Flag for the following Deployment: " + $advertID + " Source: " + $siteserver)
The above code is designed so that you can just run it to enable a single task sequence - just supply the SiteServer, SiteCode and AdvertID for the TS on the command line and you're good to cache.
If you want to automate this (and why wouldn't you?) for all Task Sequences, just create a Status Filter Rule:
In the Configuration Manager Console, navigate to Administration > Overview > Site Configuration > Sites.
In the Home tab click Settings > Status Filter Rules, click Create and the Create Status Filter Rule Wizard will show.
On the General page fill in your Rule Name e.g. 'Enable BranchCache For Task Sequences' and select the following criteria:
Select Source and then select SMS Provider. Set the SiteCode, and the Site Server to your own site settings.
Select Message Type: Audit, and Message ID and fill in 30006 which is the Status Message for the creation of a Deployment.
As the 30006 message covers other deployment types such as Regular Package, Driver Install etc., the above code checks that it is indeed a Task Sequence (PackageType=4).
In the Action tab, set the Program to:
"C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe" "set-executionpolicy bypass"; "c:\MyStatusFilterRules\setadvertflags.ps1 '%msgsys' '%msgsc' '%msgis02'"
This runs the script with the Computername, Sitecode and AdvertID arguments. All being well - you should see a logfile with a line for each successful run of this script - in the Logs folder on the the site server - with all the other SCCM logfiles.
You also need to bump up the priority of your newly created rules, so they get processed. As shown below, move them up to just above the 'Write Audit Messages To The Site Database' rule.
As always folks, we advise you to test, test, and test again!
Download the Script and instructions: [wpdm_package id='11827']
P.S - You can use this in conjunction with our FREE BranchCache for OSD Toolkit - BranchCache Fur Alles!
UPDATE! On further testing we found that if the Task Sequence deployment properties are edited, the BranchCache flag is reset to 0, so to work around this you need to set a second Status Filter Rule which is triggered by Message ID 30007 so that if you edit the deployment the flag will stay set.
cheers
Phil 2Pint