Microsoft

Microsoft Endpoint Configuration Manager Feedback

Suggestion box powered by UserVoice

Anonymous

My feedback

  1. 157 votes
    Vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    10 comments  ·  Ideas » PowerShell  ·  Flag idea as inappropriate…  ·  Admin →
    An error occurred while saving the comment
    Anonymous commented  · 

    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.

    /snip

    Set-Location $SiteDrive
    #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)
    $App1XML.DeploymentTypes[$i].Requirements
    #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
    Write-Host $AppName.LocalizedDisplayName
    }

    }
    }

    /endsnip

Feedback and Knowledge Base