powershell 将AMP优先级设置为指定值。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 将AMP优先级设置为指定值。相关的知识,希望对你有一定的参考价值。

#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

以上是关于powershell 将AMP优先级设置为指定值。的主要内容,如果未能解决你的问题,请参考以下文章

我可以为 PowerShell 中的参数指定条件默认值吗?

以百分比指定两个 UIView 的约束

将线程优先级设置为高 C

arcgis叠加的优先级

将默认值设置为列代码优先方法[重复]

指定值约束的通用语言