SCCM Client Cache Maintenance – Configuration Baseline

Many of you would have found at some point you have had to deal with applications not deploying to due client cache directories being full. Typically the way around this is to run a PowerShell command at the machine / collection to clear this down or on the client using the “Delete Files” button on the Cache tab of the SCCM client.

There is a much easier way of maintaining cache directories automatically though, by using a Configuration Baseline to monitor your machines and clear down folder that are either no longer required due to applications being withdrawn or are beyond a retention range for which you could like to set.

In the below walk through we take you through adding a Configuration Item and Baseline for this purpose. The PowerShell script looks for inactive applications, applications with folders older than the retention range specified (14 days in this example) and misc folders contained within the ccmcache directory which can be removed.

Create A Configuration Item

Open the SCCM Management console and under Assets and Compliance\Compliance  Settings select Configuration Item. Now create a new Configuration Item

Select Operating Systems

Pick the Operating Systems that you which to apply the CI to:

Add Settings

Click on New on this screen and select “Script” under Settings Type:

Discovery & Remediation Scripts

Now enter your Discovery and Remediation Scripts

Detection Script

Remediation Script

Create A New Rule

Here we will select the settings previously created and set a target value for the new rule


Now the Configuration Item is in place, we can go onto setting up the Baseline to deploy to your chosen Collection.

Create A New Configuration Baseline

Create your new Configuration Baseline, Select the Configuration Item you set up in the previous steps and click OK.



The Final Step is to deploy your newly created Configuration Baseline to a chosen collection.

Now sit back, relax and let your Configuration Baseline take care of maintaining your client cache folders 😀

Note: As always the scripts provided are used at your own risk and should be tested against limited collections.

 

(1624)

comments
  • Jessie
    Posted at 9:29 pm 21st February 2017
    Jessie
    Reply
    Author

    This is a stupid question, but after that last step you would than deploy it to your collections correct?

    • Maurice Daly
      Posted at 9:58 pm 21st February 2017
      Maurice Daly
      Reply
      Author

      That is correct. You need to simply deploy the CB to a collection of your choice (obviously taking caution and testing against a test collection is recommended). I have added an extra screenshot to clarify the final step.

  • Jessie
    Posted at 10:44 pm 21st February 2017
    Jessie
    Reply
    Author

    Awesome thanks

  • Jessie
    Posted at 9:31 pm 23rd February 2017
    Jessie
    Reply
    Author

    quick question, I am testing this with a test collection for some odd reason I get an error message stating (Incorrect function) error id 0x80070001, error category: discovery. Any idea what this issue may be?

    • Maurice Daly
      Posted at 11:34 pm 23rd February 2017
      Maurice Daly
      Reply
      Author

      What happens if you run the contents of the function manually in a PS session on a client?

  • Jessie
    Posted at 4:54 am 24th February 2017
    Jessie
    Reply
    Author

    it seemed to have worked on one machine running windows 7, but aside from that this is the error message I pulled from dcmwmiprovider.log:

    ScriptProvider::CreateInstanceEnumAsync – Script Execution Returned :1, Error Message:You must provide a value expression on the right-hand side of the ‘-‘ operator.
    At C:\Windows\CCM\SystemTemp\26e9fa0e-f85a-4eb3-b599-904442947742.ps1:16 char:9
    3
    + $PurgeApps = $SCCMClient.GetCacheInfo().GetCacheElements() | Where-Object
    { ($_.ContentID – <<<< notin $PendingList.PackageID) -and ((Test-Path -Path $_
    .Location) -eq $true) -and ($_.StartTime -gt (Get-Date).AddDays(- $MaxRetention
    )) }
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : ExpectedValueExpression

    • Maurice Daly
      Posted at 7:22 am 24th February 2017
      Maurice Daly
      Reply
      Author

      Hi Jessie. You’ll need to update the version of PowerShell running on your Windows 7 machine. By the looks of the error you are probably running version 2.0.

  • Leave a Reply