使用 SCCM 中的 Powershell 配置规则以检测部署类型的存在

Configure rules to detect the presence of a deployment type using Powershell in SCCM

我已经在 Powershell 脚本上工作了好几天,以自动执行非常乏味的 SCCM 应用程序创建过程,我 运行 遇到了一个我还没有找到答案的问题。

这是我目前的情况:

Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386", "\bin\configurationmanager.psd1")

$deployTypeHash = @{
        applicationName = "TestApp"
        deploymentTypeName = "TestApp"
        ContentLocation = "\A\Network\Path"
        InstallCommand = "Install Command"
        UninstallCommand = "Uninstall Command"
        ScriptLanguage = 'PowerShell'
        InstallationBehaviorType = 'InstallForSystem'
        LogonRequirementType = 'WhetherOrNotUserLoggedOn'
        UserInteractionMode = 'Hidden'
        MaximumRuntimeMins = 120
        EstimatedRuntimeMins = 20  
        AddDetectionClause = ""
        ValueName = "UninstallString"
} 
$cla1 =  New-CMDetectionClauseRegistryKeyValue -Hive LocalMachine `
                                                      -Is64Bit `
                                                      -KeyName "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\!$($configCM.application.name)" `
                                                      -Existence  `
                                                      -PropertyType String `
                                                      -ValueName $($deployTypeHash.ValueName) 
$logical1 = $cla1.Setting.LogicalName

#COMMENT### $cla1.Connector = 'Or'


$cla2 = New-CMDetectionClauseRegistryKeyValue -Hive LocalMachine `
                                                     -Is64Bit `
                                                     -KeyName "SOFTWARE\WOW6432\Microsoft\Windows\CurrentVersion\Uninstall\!$($configCM.application.name)" `
                                                     -Existence  `
                                                     -PropertyType String `
                                                     -ValueName "UninstallString" 
 $logical2 = $cla1.Setting.LogicalName

 #COMMENT### $cla2.Connector = 'Or'

Add-CMScriptDeploymentType -ContentLocation $($deployTypeHash.ContentLocation) `
                               -DeploymentTypeName $($deployTypeHash.deploymentTypeName) `
                               -InstallCommand $($deployTypeHash.InstallCommand) `
                               -AddDetectionClause @($cla1, $cla2) `
                               -GroupDetectionClauses @($logical1, $logical2) `
                               -ApplicationName $($deployTypeHash.applicationName) `
                               -UninstallCommand $($deployTypeHash.UninstallCommand) `
                               -InstallationBehaviorType $($deployTypeHash.InstallationBehaviorType) `
                               -LogonRequirementType $($deployTypeHash.LogonRequirementType) `
                               -MaximumRuntimeMins $($deployTypeHash.MaximumRuntimeMins) `
                               -UserInteractionMode $($deployTypeHash.UserInteractionMode) `
                               -SlowNetworkDeploymentMode Download | Out-Null

我希望能够更改用于比较部署类型连接器中的注册表项的逻辑表达式的值(从 'And' 到 'Or'),但是 none 到目前为止,我的尝试都使用这种方法(在评论中)。

有人知道如何完成这个或更好的方法吗?

谢谢

Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386", "\bin\configurationmanager.psd1")

$deployTypeHash = @{
        applicationName = "TestApp"
        deploymentTypeName = "TestApp"
        ContentLocation = "\A\Network\Path"
        InstallCommand = "Install Command"
        UninstallCommand = "Uninstall Command"
        ScriptLanguage = 'PowerShell'
        InstallationBehaviorType = 'InstallForSystem'
        LogonRequirementType = 'WhetherOrNotUserLoggedOn'
        UserInteractionMode = 'Hidden'
        MaximumRuntimeMins = 120
        EstimatedRuntimeMins = 20  
        AddDetectionClause = ""
        ValueName = "UninstallString"
} 
$cla1 =  New-CMDetectionClauseRegistryKeyValue -Hive LocalMachine `
                                                      -Is64Bit `
                                                      -KeyName "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\!$($configCM.application.name)" `
                                                      -Existence  `
                                                      -PropertyType String `
                                                      -ValueName $($deployTypeHash.ValueName) 
$logical1 = $cla1.Setting.LogicalName


$cla2 = New-CMDetectionClauseRegistryKeyValue -Hive LocalMachine `
                                                     -Is64Bit `
                                                     -KeyName "SOFTWARE\WOW6432\Microsoft\Windows\CurrentVersion\Uninstall\!$($configCM.application.name)" `
                                                     -Existence  `
                                                     -PropertyType String `
                                                     -ValueName "UninstallString" 
$logical2 = $cla2.Setting.LogicalName


Add-CMScriptDeploymentType -ContentLocation $($deployTypeHash.ContentLocation) `
                               -DeploymentTypeName $($deployTypeHash.deploymentTypeName) `
                               -InstallCommand $($deployTypeHash.InstallCommand) `
                               -AddDetectionClause @($cla1, $cla2) `
                               -GroupDetectionClauses @($logical1, $logical2) `
                               -ApplicationName $($deployTypeHash.applicationName) `
                               -UninstallCommand $($deployTypeHash.UninstallCommand) `
                               -InstallationBehaviorType $($deployTypeHash.InstallationBehaviorType) `
                               -LogonRequirementType $($deployTypeHash.LogonRequirementType) `
                               -MaximumRuntimeMins $($deployTypeHash.MaximumRuntimeMins) `
                               -UserInteractionMode $($deployTypeHash.UserInteractionMode) `
                               -DetectionClauseConnector @(@{LogicalName=$logical1;Connector="or"},@{LogicalName=$logical2;Connector="or"}) `
                               -SlowNetworkDeploymentMode Download | Out-Null