none
Adding Global Condition Organizational Unit to Deployment Type via Powershell RRS feed

  • Question

  • I asked this question some time back and once again I need to create an application with about 50 deployments based on OU.

    The script works fine except for the OU rule. It is based on https://gallery.technet.microsoft.com/Add-a-Requirement-to-an-ce60681f

    You can create the deployment type normally but when you open the deployment type in console and go to the rules tab you get a blank box and a red icon and no OU is listed.

    I also see that if you export the application at that point and compare it to a deployment type where you have set the OU rule manually there is a difference in the SMS_Application\GUID\object.xml file.

    if you look in the Operands section, The top value created manually shows: <OUValue Value="OU=

    The bottom value which the script created shows: <ConstantValue Value="OU=

    Any ideas? Anyone else having success creating numerous application deployments using the Global\MachineOU condition?

    Thanks in advance for ANY help on this!

    $GlobalCondition = "MachineOU"
    $Operator = "OneOf"
    $Value = "OU=Devices,OU=Blank,OU=Blank,OU=Blank,DC=Cosco,DC=local(Include sub OU)"
    
        $GlobalConditionName = "$($GlobalCondition)_Setting_LogicalName"
    	$ExpressionBase = new-object "Microsoft.ConfigurationManagement.DesiredConfigurationManagement.CustomCollection``1[[Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Expressions.ExpressionBase]]"
    	$ConfigurationItemSettingSourceType = [Microsoft.ConfigurationManagement.DesiredConfigurationManagement.ConfigurationItemSettingSourceType]::CIM
    	$pdSettingDataType = [Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Expressions.DataType]::String
    	$pdDataType = [Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Expressions.DataType]::StringArray
    
    	$ExpressionOperator = [Microsoft.ConfigurationManagement.DesiredConfigurationManagement.ExpressionOperators.ExpressionOperator]::$operator
    	
        $Annotation = new-object Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.Annotation
    	$Annotation.DisplayName = new-object Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.LocalizableString -ArgumentList @("DisplayName", "Organizational unit (OU) One of {$Value}", $null)
    
        $ExpressionBase.Add((new-object Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Expressions.GlobalSettingReference -ArgumentList ("GLOBAL", "$GlobalCondition", $pdSettingDataType, "$GlobalConditionName", $ConfigurationItemSettingSourceType)))
    	
        $ConstantValueList = new-object Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Expressions.ConstantValueList -ArgumentList ($pdDataType)
    	$Value.Split(";") | foreach { $ConstantValueList.AddConstantValue($_) }
    	$ExpressionBase.Add($ConstantValueList)
    	$expression = new-object Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Expressions.Expression -ArgumentList @($ExpressionOperator, $ExpressionBase)
    
        $newRule = new-object Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.Rule -ArgumentList @("Rule_$([Guid]::NewGuid().ToString())", [Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.NoncomplianceSeverity]::None, $Annotation, $expression)			
    

    <DeploymentType AuthoringScopeId="ScopeId_4BDE3E61-54EB-4CE9-A43A-F5716D81E9B7" LogicalName="DeploymentType_b91dea33-2226-4315-ae03-7f0d147d78a7" Version="1">
    <Title ResourceId="Res_193576341">Site A (*.msi file)</Title>
    <Requirements>
    <Rule xmlns="http://schemas.microsoft.com/SystemsCenterConfigurationManager/2009/06/14/Rules" id="Rule_899f189b-b895-4532-9600-116db3775f7e" Severity="None" NonCompliantWhenSettingIsNotFound="false">
    	<Annotation>
    		<DisplayName Text="Organizational unit (OU) One of {OU=NewDevices,OU=Blank,OU=Blank,OU=Blank,DC=Cosco,DC=local(Include sub OU)}"/>
    		<Description Text=""/>
    	</Annotation>
    
    	<Expression>
    		<Operator>OneOf</Operator>
    		<Operands>
    			<GlobalSettingReference AuthoringScopeId="GLOBAL" LogicalName="MACHINEOU" DataType="String" SettingLogicalName="MachineOU_Setting_LogicalName" SettingSourceType="CIM" Method="Value"/>
    			<ConstantValueList DataType="StringArray">
    				<OUValue Value="OU=NewDevices,OU=Devices,OU=Devices,DC=Consco,DC=local" DataType="String" IncludesSubOU="true"/>
    			</ConstantValueList>
    		</Operands>
    	</Expression>
    </Rule>
    
    
    <DeploymentType AuthoringScopeId="ScopeId_4BDE3E61-54EB-4CE9-A43A-F5716D81E9B7" LogicalName="DeploymentType_b9f0afed-e6fc-4785-ade0-fa0586056c35" Version="1">
    <Title ResourceId="Res_839210948">Site B (*.msi file)</Title>
    <Requirements>
    <Rule xmlns="http://schemas.microsoft.com/SystemsCenterConfigurationManager/2009/06/14/Rules" id="Rule_662183cc-ae85-425d-abb6-07560754eda3" Severity="None" NonCompliantWhenSettingIsNotFound="false">
    	<Annotation>
    		<DisplayName Text="Organizational unit (OU) One of {OU=Devices,OU=Blank,OU=Blank,OU=Blank,DC=Cosco,DC=local(Include sub OU)}"/>
    		<Description Text=""/>
    	</Annotation>
    	
    	<Expression>
    		<Operator>OneOf</Operator>
    		<Operands>
    			<GlobalSettingReference AuthoringScopeId="GLOBAL" LogicalName="MachineOU" DataType="String" SettingLogicalName="MachineOU_Setting_LogicalName" SettingSourceType="CIM" Method="Value"/>
    			<ConstantValueList DataType="StringArray">
    				<ConstantValue Value="OU=Devices,OU=Blank,OU=Blank,OU=Blank,DC=Cosco,DC=local(Include sub OU)" DataType="String"/>
    			</ConstantValueList>
    		</Operands>
    	</Expression>
    </Rule>
    

    Thursday, September 14, 2017 8:26 PM

All replies

  • Hi, 

    I tried this and got the same. 

    I would suggest that you can contact the author of this script and discuss this. It will be much appreciated to post the answer here. Thanks in advance.


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, September 15, 2017 5:47 AM
    Moderator
  • Yeah we tried that. Lots of folks with same issue and no one has been able to figure it out. Adding global conditions with organizational units does not seem common I guess because nowhere on the internet can I find anyone who has solved this issue.
    Friday, September 15, 2017 1:08 PM
  • Hi, It will be much better if you can find another way around this or else, we may need to contact Microsoft for help. The only document we can rely on is the SDK which does not have such information.


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, September 21, 2017 10:18 AM
    Moderator
  • Hi,

    I have OU requirements solved in my solution. It's C# but should be easy to catch.
    The main difference is that you use AddConstantValue method that adds object of type ConstantValue,
    while I add OUValue object to ValueList inside constantValueList. OUValue is of type Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Expressions.OUValue.

    ConstantValueList constantValueList = new ConstantValueList(DataType.StringArray);
    OUValue ouValue;

    foreach (string ouName in ouNames) {
       ouValue = new OUValue(ouName, true);
       constantValueList.ValueList.Add(ouValue);
    }

    Here is a nice article to read about constructing rules: http://www.laurierhodes.info/?q=node/91






    Thursday, April 11, 2019 8:37 AM