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

How to update SCCM Enhanced Detection Method via Powershell

我找到了一种通过 Powershell 更新 DeploymentType 的方法:

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

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

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

所以,解决方案原来是你必须添加一个新的检测方法并删除旧的。没有“修改”

以下是现在自动将我的 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