如何通过Powershell更新SCCM增强检测方法

ru9i0ody  于 2023-04-12  发布在  Shell
关注(0)|答案(2)|浏览(105)

我发现了一种通过PowerShell更新DeploymentType的方法:

$AppName = "Chromium Edge"
$DT = Get-CMDeploymentType -ApplicationName $AppName
Update-CMDistributionPoint -ApplicationName $AppName -DeploymentTypeName $DT.LocalizedDisplayName

应用程序检测通过检查已安装版本的注册表值来工作。当我更新内容时,我需要更新它正在检查的版本。

它似乎是“增强检测方法”的一部分,但我不知道如何修改它。似乎有一个"set" and a "remove",但没有修改。

beq87vna

beq87vna1#

当使用[xml]为应用程序提供多个部署类型时,我在删除旧的检测规则时遇到问题。我使用Get-CMDeploymentTypeDetectionClause来获取它们:

#Get the DetectionMethodClauses of the Current DT Detection Method (so we can remove later)
$DetectionMethodClauses = Get-CMDeploymentTypeDetectionClause -InputObject $CMDeploymentType

#Remove Old Detection Method
foreach ($Clause in $DetectionMethodClauses)
{
    $LogicalName = $Clause.Setting.LogicalName
    Write-Host "Removing old Detection rule : $LogicalName"
    $CMDeploymentType | Set-CMMSIDeploymentType -RemoveDetectionClause $LogicalName
}
gopyfrb3

gopyfrb32#

所以,解决方案原来就是要增加新的检测方法,去掉旧的,没有“修改”
以下是现在自动将我的Chromium Edge应用程序检测更新到当前版本的解决方案。
这是根据Reddit Thread确定的

$AppName = "Chromium Edge"
$DTName = "Microsoft Edge - Check using registry"
    #Get DeploymentType Info
    $CMDeploymentType = get-CMDeploymentType -ApplicationName $AppName -DeploymentTypeName $DTName
    [XML]$AppDTXML = $CMDeploymentType.SDMPackageXML
    [XML]$AppDTDXML = $AppDTXML.AppMgmtDigest.DeploymentType.Installer.DetectAction.args.Arg[1].'#text'    
    #Get Detection Information from Current DT
    $DetectionRegKey = $AppDTDXML.EnhancedDetectionMethod.Settings.SimpleSetting.RegistryDiscoverySource.key
    $DetectionRegKeyValueName = $AppDTDXML.EnhancedDetectionMethod.Settings.SimpleSetting.RegistryDiscoverySource.ValueName
    #Get the LogicalName of the Current DT Detection Method (so we can remove later)
    $OrigLogicalName = $AppDTDXML.EnhancedDetectionMethod.Rule.Expression.Operands.SettingReference.SettingLogicalName
    
    #Create Updated Detection Method
    $UpdatedRegistryDetection = New-CMDetectionClauseRegistryKeyValue -Hive LocalMachine -KeyName $DetectionRegKey -PropertyType Version -ValueName $DetectionRegKeyValueName -ExpressionOperator GreaterEquals -Value -ExpectedValue $selectedVersion
    Write-Host " Created Detection Method for Key: $DetectionRegKey Property: $DetectionRegKeyValueName Value: $SelectedVersion" -ForegroundColor Green
    #Write-CMTraceLog -Message " Created Detection Method for Key: $DetectionRegKey Property: $DetectionRegKeyValueName Value: $DownloadPreProdFileVersion" -Type 1
    #Add Newly Created Detection Method
    Write-Host " Adding Detection Method to App" -ForegroundColor Green
    #Write-CMTraceLog -Message " Adding Detection Method to App $EdgePreProd" -Type 1
    $SetDetection = Set-CMMSIDeploymentType -ApplicationName $AppName -DeploymentTypeName $DTName -AddDetectionClause $UpdatedRegistryDetection
    #Remove Old Detection Method
    Write-Host " Removing old Detection Method from App" -ForegroundColor Green
    #Write-CMTraceLog -Message " Removing old Detection Method from Ap" -Type 1
    $CMDeploymentType | Set-CMMSIDeploymentType -RemoveDetectionClause $OrigLogicalName

    #Update Software Version Field in App
    Write-Host " Updating Software Version on App to $SelectedVersion" -ForegroundColor Green
    #Write-CMTraceLog -Message " Updating Software Version on App from $PreProdFileVersion to $DownloadPreProdFileVersion" -Type 1
    Set-CMApplication $AppName -SoftwareVersion $selectedVersion
    #Update Distribution Points
    Write-Host " Updating Distribution Points" -ForegroundColor Green
    #Write-CMTraceLog -Message " Updating Distribution Points" -Type 1
    Update-CMDistributionPoint -ApplicationName $AppName -DeploymentTypeName $DTName

相关问题