Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active April 26, 2017 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/42994f938e5d09e81864cf3dc26822f6 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/42994f938e5d09e81864cf3dc26822f6 to your computer and use it in GitHub Desktop.
Create MIM MPR
# -- Create MPR ---
[xml]$MPRXML = @'
<Lithnet.ResourceManagement.ConfigSync>
<Operations>
<ResourceOperation operation="None" resourceType="Set" id="MPRID">
<AnchorAttributes>
<AnchorAttribute>DisplayName</AnchorAttribute>
</AnchorAttributes>
<AttributeOperations>
<AttributeOperation operation="replace" name="DisplayName">__SET</AttributeOperation>
</AttributeOperations>
</ResourceOperation>
<ResourceOperation operation="None" resourceType="WorkflowDefinition" id="SyncRuleWorkflowID">
<AnchorAttributes>
<AnchorAttribute>DisplayName</AnchorAttribute>
</AnchorAttributes>
<AttributeOperations>
<AttributeOperation operation="replace" name="DisplayName">__Workflow</AttributeOperation>
</AttributeOperations>
</ResourceOperation>
<!-- Create transitionIn MPR -->
<ResourceOperation operation="Add Update" resourceType="ManagementPolicyRule" id="__MPRID">
<AnchorAttributes>
<AnchorAttribute>DisplayName</AnchorAttribute>
</AnchorAttributes>
<AttributeOperations>
<AttributeOperation operation="replace" name="DisplayName">__MPR</AttributeOperation>
<AttributeOperation operation="replace" name="Description">This MPR adds a Sync Rule to provision users to DEV AD when user connectors are detected in PROD AD</AttributeOperation>
<AttributeOperation operation="replace" name="ActionParameter">*</AttributeOperation>
<AttributeOperation operation="replace" name="ActionType">TransitionIn</AttributeOperation>
<AttributeOperation operation="replace" name="ActionWorkflowDefinition" type="xmlref">AddInitialLoadOfDEVADUsersSyncRule</AttributeOperation>
<AttributeOperation operation="replace" name="Disabled">false</AttributeOperation>
<AttributeOperation operation="replace" name="GrantRight">false</AttributeOperation>
<AttributeOperation operation="replace" name="ManagementPolicyRuleType">SetTransition</AttributeOperation>
<AttributeOperation operation="replace" name="ResourceFinalSet" type="xmlref">DEVADUsersSet</AttributeOperation>
</AttributeOperations>
</ResourceOperation>
</Operations>
</Lithnet.ResourceManagement.ConfigSync>
'@
# Get and update the MPR DisplayName's, reference the Tansition Set Displayname and the Workflow DisplayName
$displaynames = $MPRXML | Select-Xml -Xpath "//AttributeOperation[@name='DisplayName']"
$displaynames.node
foreach ($name in $displaynames){
if($name.Node.'#text'.Equals("__MPR")){$name.Node.'#text' = $SyncRuleIDDisplayName +" MPR"}
if($name.Node.'#text'.Equals("__Workflow")){$name.Node.'#text' = $SyncRuleIDDisplayName +" Workflow"}
if($name.Node.'#text'.Equals("__SET")){$name.Node.'#text' = $SyncRuleIDDisplayName +" Set"}
}
# Get and update the MPR Description
$description = $MPRXML | Select-Xml -Xpath "//AttributeOperation[@name='Description']"
$description.node.'#text' = "MPR for "+$SyncRuleIDDisplayName
# Get and update the ID's for the MPR, Set and Workflow referenced by the MPR
$id = $MPRXML | Select-Xml -Xpath "//ResourceOperation[@id]"
$id.node
foreach ($idname in $id){
if($idname.Node.id.Equals("__MPRID")){$idname.Node.id = $MPRIDName } #MPR
if($idname.Node.id.Equals("MPRID")){$idname.Node.id = $SetIDName} #SET
if($idname.Node.id.Equals("SyncRuleWorkflowID")){$idname.Node.id = $WorkflowIDName} #Workflow
}
# Update Action Worflow Definition Text
$actionwf = $MPRXML | Select-Xml -Xpath "//AttributeOperation[@name='ActionWorkflowDefinition']"
$actionwf.Node.'#text' = $WorkflowIDName
# Update the Resultant Set
$resultantset = $MPRXML | Select-Xml -Xpath "//AttributeOperation[@name='ResourceFinalSet']"
$resultantset.Node.'#text' = $SetIDName
# Output MPR XML File
$MPRXML.save($WorkingDirectory[1]+"\CreateNewMPR.xml")
# Create MPR
Import-RMConfig -File ($WorkingDirectory[1]+"\CreateNewMPR.xml") -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment