Managing Priorities of Client Policies and A/V Policies in SCCM
Anyone who has had to create a policy for client settings, or anti-virus policies and needed to jump it up in priority has gone through the whole scenario of right-click...increase priority, right-click...increaser priority...right-click....increase priority. While waiting for the console to refresh after ever click. While all in all..it isn't *that* difficult, personally I'm pretty lazy. And the things that I love about SCCM is that it let's me be lazy. So I thought to myself, while increasing the priority of some client settings, there has to be a better way!
And there was....Below you will find two functions, which can easily be converted into stand-alone scripts. The functions do require a few things. First, you must have the ConfigurationManager.psd1 imported and working, and your location needs to be whatever your three-letter site code is. These scripts do not do any error-checking.
Function: Move-CMAntiMalwarePolicy
Purpose: Move an SCCM 2012 SCEP policy's priority up or down a specified number of times.
Parameters:
1. -times: number of times to a move policy's priority up or down
-UporDown: Number of positions to move the policy's priority
-PolicyName: The name of the policy to be moved. If there are spaces in the name use quotes. Example: Move-CMAntiMalwarePolicy -times 4 -UporDown "Up" -PolicyName "Workstation Default Policy" Result: Moves the Anti-Malware policy called Workstation Default Policy up in priority four times Function:
01.Function Move-CMAntiMalwarePolicy
02.{
03.Param(
04. [Parameter(Mandatory=$true,Position=1)]
05. [int]$times,
06. [Parameter(Mandatory=$true,Position=2)]
07. [ValidateSet("Up", "Down")]
08. [string]$UporDown,
09. [Parameter(Mandatory=$true,Position=3)]
10. [string]$PolicyName
11.)
12. switch ($UporDown)
13. {
14. "Up"
15. {
16. echo "I'm going up"
17. $i = 0
18. do
19. {
20. $i++
21. Set-CMAntimalwarePolicy -Name $PolicyName -Priority Increase
22. echo "I went Up $i"
23. }
24. while ($i -lt $times)
25. }
26. "Down"
27. {
28. echo "I'm going down"
29. $i = 0
30. do
31. {
32. $i++
33. Set-CMAntimalwarePolicy -Name $PolicyName -Priority Decrease
34. echo "I went down $i"
35. }
36. while ($i -lt $times)
37. }
38. }
39.}
Function: Move-CMClientSettings
Purpose: Move an SCCM 2012 client policy's priority up or down a specified number of times.
Parameters:
-times: number of times to move a policy's priority up or down
-UporDown: Number of positions to move the policy's priority
-ClientSettings: The name of the settings to be moved. If there are spaces in the name use quotes. Example: Move-CMClientSettings -times 4 -UporDown "Up" -ClientSettings "Workstation Default Policy" Result: Moves the client policy called Workstation Default Policy up in priority four times
01.Function Move-CMClientSettings
02.{
03.Param(
04. [Parameter(Mandatory=$true,Position=1)]
05. [int]$times,
06. [Parameter(Mandatory=$true,Position=2)]
07. [ValidateSet("Up", "Down")]
08. [string]$UporDown,
09. [Parameter(Mandatory=$true,Position=3)]
10. [string]$ClientSettings
11.)
12.switch ($UporDown)
13. {
14. "Up"
15. {
16. echo "I'm going up"
17. $i = 0
18. do
19. {
20. $i++
21. Set-CMClientSetting -Name $ClientSettings -Priority Increase
22. echo "I went Up $i"
23. }
24. while ($i -lt $times)
25. }
26. "Down"
27. {
28. echo "I'm going down"
29. $i = 0
30. do
31. {
32. $i++
33. Set-CMClientSetting -Name $ClientSettings -Priority Decrease
34. echo "I went down $i"
35. }
36. while ($i -lt $times)
37. }
38. }
39.}
..And that's it!