Skip to content

Instantly share code, notes, and snippets.

@Ioan-Popovici
Created February 6, 2019 14:16
Show Gist options
  • Save Ioan-Popovici/da8bf688b7ee11895db3dcedb2da4eb2 to your computer and use it in GitHub Desktop.
Save Ioan-Popovici/da8bf688b7ee11895db3dcedb2da4eb2 to your computer and use it in GitHub Desktop.
Sets AMP priority to a specified value by increasing or decreasing the priority as required.
#region Function Set-AMPPriority
Function Set-AMPPriority {
<#
.SYNOPSIS
Sets AMP priority to a specified value.
.DESCRIPTION
Sets AMP priority to a specified value by increasing or decreasing the priority as required.
.PARAMETER Name
Specifies the AMP name.
.PARAMETER Priority
Specifies required priority.
.EXAMPLE
Set-AMPPriority -Name 'SomeAMPName' -Priority '2'
.INPUTS
System.String.
.OUTPUTS
None.
.NOTES
This is an internal script function and should typically not be called directly.
.LINK
https://SCCM.Zone
.LINK
https://SCCM.Zone/Git
.COMPONENT
Configuration Manager Client
.FUNCTIONALITY
Set AMP Priority
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,Position=0)]
[ValidateNotNullorEmpty()]
[Alias('na')]
[string]$Name,
[Parameter(Mandatory=$true,Position=0)]
[ValidateNotNullorEmpty()]
[Alias('pr')]
[string]$Priority
)
Begin {
## Set script to fail on any error
$ErrorActionPreference = 'Stop'
## Import SCCM PSH module and changing context
Try {
Import-Module -Name $env:SMS_ADMIN_UI_PATH.Replace('\bin\i386','\bin\configurationmanager.psd1')
}
Catch {
Throw "Could not Import CM PSH module. `n $_"
}
Try {
# Get the CMSITE SiteCode and change connection context
$SiteCode = Get-PSDrive -PSProvider 'CMSITE'
# Change the connection context
Set-Location "$($SiteCode.Name):\"
}
Catch {
Throw "Could not set connection context. `n $_"
}
}
Process {
Try {
## Get AMP current priority
[string]$CurrentPriority = (Get-CMAntimalwarePolicy -Name $Name).Priority
## Set AMP priority
While ($CurrentPriority -ne $Priority) {
If ($CurrentPriority -lt $Priority) {
Set-CMAntimalwarePolicy -Name $Name -Priority 'Decrease'
}
Else {
Set-CMAntimalwarePolicy -Name $Name -Priority 'Increase'
}
# Get AMP current priority
$CurrentPriority = (Get-CMAntimalwarePolicy -Name $Name).Priority
}
}
Catch {
Throw "Could not change priority [$Priority] for AMP [$Name]. `n $_"
Break
}
Finally {
Write-Output -InputObject "Priority for AMP [$Name] is [$CurrentPriority]."
}
}
End {
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment