Last active
April 26, 2017 00:20
-
-
Save darrenjrobinson/ff0d1ee33224e47b887c7e97e840f510 to your computer and use it in GitHub Desktop.
Create MIM Workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- WORKFLOW -- | |
[xml]$WorkflowXML = @' | |
<Lithnet.ResourceManagement.ConfigSync> | |
<Operations> | |
<!-- Create Workflow --> | |
<ResourceOperation operation="Add Update" resourceType="WorkflowDefinition" id="SyncRuleWorkflowID"> | |
<AnchorAttributes> | |
<AnchorAttribute>DisplayName</AnchorAttribute> | |
</AnchorAttributes> | |
<AttributeOperations> | |
<AttributeOperation operation="add" name="DisplayName">SyncRuleWorkflowID</AttributeOperation> | |
<AttributeOperation operation="add" name="Description">WorkflowForOutboundSyncRule</AttributeOperation> | |
<AttributeOperation operation="add" name="XOML" type="file">C:\Path\XOML.xml</AttributeOperation> | |
<AttributeOperation operation="add" name="RequestPhase">Action</AttributeOperation> | |
<AttributeOperation operation="add" name="RunOnPolicyUpdate">false</AttributeOperation> | |
</AttributeOperations> | |
</ResourceOperation> | |
</Operations> | |
</Lithnet.ResourceManagement.ConfigSync> | |
'@ | |
[xml]$WorkflowXOML = @' | |
<ns0:SequentialWorkflow ActorId="00000000-0000-0000-0000-000000000000" RequestId="00000000-0000-0000-0000-000000000000" x:Name="SequentialWorkflow" TargetId="00000000-0000-0000-0000-000000000000" WorkflowDefinitionId="00000000-0000-0000-0000-000000000000" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:Microsoft.ResourceManagement.Workflow.Activities;Assembly=Microsoft.ResourceManagement, Version=4.4.1302.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> | |
<ns0:SynchronizationRuleActivity AddValue="{x:Null}" Action="Add" SynchronizationRuleId="1234a4567-ab12-34c5-9988-123456789012" AttributeId="00000000-0000-0000-0000-000000000000" RemoveValue="{x:Null}" x:Name="authenticationGateActivity1"> | |
<ns0:SynchronizationRuleActivity.Parameters> | |
<x:Array Type="{x:Type ns0:SynchronizationRuleParameter}" /> | |
</ns0:SynchronizationRuleActivity.Parameters> | |
</ns0:SynchronizationRuleActivity> | |
<ns0:FunctionActivity Description="Populate Originating MA attribute" Destination="[//Target/_originatingMA]" FunctionExpression="<fn id="SingleValueAssignment" isCustomExpression="false"><arg>[//Target/_source]</arg></fn>" x:Name="authenticationGateActivity2" /> | |
</ns0:SequentialWorkflow> | |
'@ | |
#Find all nodes of type "Resource Operation" with attribute ID and update | |
$ids = $WorkflowXML | Select-Xml -Xpath "//ResourceOperation[@id]" | |
$ids.node.id | |
Edit-XmlNodes $WorkflowXML -xpath "/Lithnet.ResourceManagement.ConfigSync/Operations/ResourceOperation[@id='SyncRuleWorkflowID']/@id" -value $WorkflowIDName | |
$WorkflowXML.'Lithnet.ResourceManagement.ConfigSync'.Operations.ResourceOperation.id | |
# Get and update the Workflow DisplayName | |
$displayname = $WorkflowXML | Select-Xml -Xpath "//AttributeOperation[@name='DisplayName']" | |
$displayname.node.'#text' = $SyncRuleIDDisplayName +" Workflow" | |
# Get and update the Workflow Description | |
$description = $WorkflowXML | Select-Xml -Xpath "//AttributeOperation[@name='Description']" | |
$description.node.'#text' = "Workflow for "+$SyncRuleIDDisplayName | |
# Get and update the XOML Path | |
$xomlpath = $WorkflowXML | Select-Xml -Xpath "//AttributeOperation[@name='XOML']" | |
$xomlpath.node.'#text' = $WorkingDirectory[1]+"\NewWorkflowXOML.xml" | |
# Output Workflow | |
$WorkflowXML.save($WorkingDirectory[1]+"\CreateNewWorkflow.xml") | |
# Update the Workflow XOML for the corresponding SyncRule ID | |
$node = $WorkflowXOML.SequentialWorkflow.SynchronizationRuleActivity | |
$node.SynchronizationRuleId = $importedSyncRuleObjID | |
# Output Workflow XOML | |
$WorkflowXOML.save($WorkingDirectory[1]+"\NewWorkflowXOML.xml") | |
# Create Workflow | |
Import-RMConfig -File ($WorkingDirectory[1]+"\CreateNewWorkflow.xml") # -Preview -Verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment