add a powershell possibility to add requirements to a deploymenttype of an application
At the moment it is not easy to add requirements to an application deploymenttype with PowerShell. I think many of us would benefit if this would be simplified.
Changing status back to “Started” as there’s more work to do here. We plan to simplify adding requirements to DTs as well as complete the missing scenarios for detection methods in a future release. Stay tuned for more updates.
I don't remember where I got the bones of this - but it works by getting the requirement off one deploymenttype and applying that object to the other deploymenttype. snip below assumes you've set a $SiteDrive variable already.
#Select an application and deploymenttype with a requirement you want to copy
$name1 = "James_Baseline_WorkstationOS"
$App1 = Get-CMApplication -Name $name1
$i = 0
$DeploymentTypeName = Get-CMDeploymentType -DeploymentTypeName $name1 -ApplicationName $name1
$App1XML = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::DeserializeFromString($app1.SDMPackageXML)
#Get the requirement itself
$OSRule = $App1XML.DeploymentTypes[$i].Requirements
$oAnnotation = $App1XML.DeploymentTypes[$i].Requirements.annotation
$oOSExpression = $App1XML.DeploymentTypes[$i].Requirements.Expression
$oSeverity = $App1XML.DeploymentTypes[$i].Requirements.severity
#Create a rule to be applied to other deploymenttypes
$newrule = new-object "Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.Rule" -ArgumentList (("Rule_" + [Guid]::NewGuid().ToString()), $oSeverity, $oAnnotation, $oOSExpression)
#Now apply all this on other Apps
#get applications - edit the filter for the app(s) you want to target
$filter1 = "*"
$Apps = Get-CMApplication -Name $filter1
foreach ($AppName in $apps)
$DTs = Get-CMDeploymentType -ApplicationName $($AppName.LocalizedDisplayName)
Foreach ($DT in $DTs)
#get only those that don't already have the requirement set'
if ($DT -notmatch $($OSRule.name))
#apply the rule created to the deploymenttype - creates the requirement
$DT | Set-CMDeploymentType -AddRequirement $newrule
Start-Sleep -Seconds 1
Seconding the request for some way to actually make use of -addRequirement - this was stated as "this is the type of improvement we have in our backlog to make in the future." in 2015... 3 years ago, and yet apparently doesn't exist yet?
Struggling with the -AddRequirement to the deplyoment type and we need it for a large project for automated creation of applications.
Why is there no easy way to add requirements to the deployment types via PowerShell and when will this be fixed? I see the initial post is from 2 years ago.
Tony Morrow commented
Enhanced Detection Rules and Requirements are two different things. For example, we use a requirement to ensure the ActiveX version of Adobe Flash player is not installed on computers running Windows 8.1+ because the install will fail. Currently I do not see an easy way to define a "requirement" for a deployment type. The "Add-CM***DeploymentType CMDlet has a parameter called "-AddRequirement", but it requires a "Microsoft.SystemManagementServer.DesiredConfigurationManagement.Rules.Rule" object and I don't see a cmdlet to create that type of object.
Raphael Perez from http://www.thedesktopteam.com created a powershell cmdlet in 2015 to define a requirement and add it to a deployment type, but it would be really helpful to define requirement objects and feed them to the deploymenttype cmdlets, similar to the cmdlets for creating detection rules and dependencies.
Eden Lincoln Ferreira de Oliveira commented
Since I use "UDA" for all my applications, there are two options I would need to add to the application creation process, however I cant figure out which Cmdlets I would need to add to my script.
I am running ConfigMgr 1610 + powershell 5.0 and SRV 2012 R2
1) On the Application properties
Add a requirement Type:
Condition: Primary Device
Rule Type: Value
2) Deployment Setting
Check off the Option: Pre-Deploy software to the user's primary device
Thank you for your help in advance
Dawn Wertz commented
The link is for detection methods, I am looking for a way to add the requirements
+1 to Robin Verbeek's request. MS documentation is severally lacking on this subject and most people posting work around are using WMI which defeats the purpose of using PS Cmdlets IMO.
Jonathan Walz commented
I would like to see cmdlets for adding enhanced detection methods to existing deployment types.
Raphael Perez commented
when creating a deployment type, the detection method only gives you option for MSI Product code or Script based.
it would be great if the cmdlets also gives you the ability for file system as well as registry, like the UI does
AdminAdam Meltzer (ConfigMgr Product Team) (Software Engineer, Microsoft Endpoint Configuration Manager) commented
Today there is limited support for adding requirements to an application. You can use the DCM SDK to create requirement rules and then add them using -AddRequirements in Add-CMDeploymentType/Set-CMDeploymentType.
I realize this is not as simple as just having a generic New-CMRequirementRule type cmdlet and this is the type of improvement we have in our backlog to make in the future.
Thanks for your feedback on this.