There is the GUI-way and the Powershell-way…
This scripts creates:
- A Configuration Item
- A Baseline
- A Baseline Deployment
The only thing you need is admin-rights in the ConfigMgr, select schedule-inteval and count and what collection to deploy to.
note: At the end when “New-CMBaselineDeployment” creates the deployment you can choose if you want it to only “Monitor” or to “Remediate”. If you add the option “-EnableEnforcement $True” at the end the action will be set to “Remediate”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<# ************************************************************************************************************************ Created: 2019-03-06 Version: 1.0 Disclaimer: This script is provided "AS IS" with no warranties Author - Christian Damberg Twitter: @DambergC Blog : https://www.damberg.org ************************************************************************************************************************ #> #name and description of the Configuration Item $CI_name = 'SCCM Cache-Cleaner item' $CI_desc = 'To do maintanence on Cache-folder' #name of setting and path to powershellscripts $Setting_name = 'Clean SCCM cache-folder' $Path_discoverScript = 'E:\Script\discover.ps1' $Path_remediationscript = 'E:\Script\remi.ps1' #name and description of the rule $rule_name = 'Clean Cache-folder rule' $rule_Desc = 'Clean cache-folder' #Name, description and targetcollection for the baseline $baseline_name = 'Clean cache-folder Baseline' $baseline_desc = 'Maintanence on lokal Cache-folder' $collection_name = 'All systems' #BaselineDeployment Schedule $scheduleInterval = 'Days' #days, minutes, hour $ScheduleCount = '14' #First you need to create an Configuration Item $CIObject = New-CMConfigurationItem -Name $CI_name -CreationType WindowsOS -Description $CI_desc #Create the settings by using powershell script $Setting = Add-CMComplianceSettingScript -InputObject $CIObject -settingName $Setting_name -DataType Integer -DiscoveryScriptLanguage PowerShell -DiscoveryScriptFile $Path_discoverScript -RemediationScriptLanguage PowerShell -RemediationScriptFile $Path_remediationscript -noRule #Create the Settings Rule $setting2 = $CIObject | Get-CMComplianceSetting -SettingName $Setting_name $CIRule = $Setting2 | New-CMComplianceRuleValue -ExpressionOperator IsEquals -RuleName $rule_name -ExpectedValue 0 -NoncomplianceSeverity Critical -RuleDescription $rule_desc -Remediate $CIRuleAdded = Add-CMComplianceSettingRule -InputObject $CIObject -Rule $CIRule #Create the baseline New-CMBaseline -Name $baseline_name -Description $baseline_desc #add the CI to the baseline Set-CMBaseline -Name $baseline_name -AddOSConfigurationItem $CIObject.ci_id #Create the schedule when de deployment of the baseline should accur. $BaselineSchedule = New-CMSchedule -RecurInterval $scheduleInterval -RecurCount $ScheduleCount #Deploy the baseline to the target collection New-CMBaselineDeployment -CollectionName $collection_name -name $baseline_name -EnableEnforcement $true -Schedule $BaselineSchedule |
You will need two script from Maurice Daly from his blogpost SCCM Client Cache Maintenance – Configuration Baseline