Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.