I've been working for days on a Powershell script to automate the oh so tedious creating process of SCCM applications and I've run into an issue that I didn't find an answer on yet.
Heres what I have so far:
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
I would like to be able the change the value of the logical expression used to compare registry keys in the connector of the deployment type (from 'And' to 'Or'), but none of my attempts has worked so far using this method (in comment).
Anybody knows how to accomplish this or a better way to do it maybe?
Thank you
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