Search code examples
powershellsccm

How to update SCCM Enhanced Detection Method via Powershell


I have found a way to update the DeploymentType via Powershell:

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

The application detection works via checking the registry value for the version that is installed. When I update the content, I need to update the version that it is checking against.

Detection Rule using Version in Registry

It appears to be part of the "Enhanced Detection Method" but I am at a loss about how to modify it. There appears to be a "set" and a "remove" but no modify.


Solution

  • So, the solution turns out that you have to add a new detection method and remove the old one. There is no "modify"

    The following is the solution that now automatically updates my Chromium Edge Application detection to the current version.

    This was determined from this 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