FIM ScriptBox Item

Summary

This script replaces the MA ID references in portal sync rules. If you run into the errors described in this post and get the "sync-rule-validation-parsing-error; referenced MA has been deleted" you can't open the sync rules in the portal to correct the issue. This powershell script will replace the reference ID's on all affected sync rules.

 

 Important
Make sure you have the correct MA id references!.

 

Script Code

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
cls
#------------------------------------------------------------------------------------------------------
set-variable -name URI     -value "http://localhost :5725/resourcemanagementservice"    -option constant
# this is the incorrect value that you wish to replace
set-variable -name OldMAID -value "{CBF5DF3A-62C5-4315-8F22-7CB264866713}" -option constant
# this is the correct value you wish to insert - Look for SyncConfig-id in the ma-data entry for your new MA
set-variable -name NewMAID -value "{5A6315D5-18D0-496C-AE0C-27A67F27785C}" -option constant
#------------------------------------------------------------------------------------------------------
write-host "`nFix incorrect MA references for sync rules"
write-host "==========================================="
#------------------------------------------------------------------------------------------------------
#Export the sync rule configuration from the service:
write-host " -Reading Synchronization Rule information"
if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) 
{add-pssnapin FIMAutomation}
$SyncRules = export-fimconfig -uri $URI `
                              -onlyBaseResources `
                              -customconfig ("/SynchronizationRule")

if($SyncRules -eq $null) {throw "Cannot find any synchronization rules - something is wrong.."} 
foreach ($SyncRule in $SyncRules) {
   $thisMAID = $SyncRule.ResourceManagementObject.ResourceManagementAttributes | `
                Where-Object {$_.AttributeName -eq "ConnectedSystem"}
   $thisMADesc = $SyncRule.ResourceManagementObject.ResourceManagementAttributes | `
                 Where-Object {$_.AttributeName -eq "Description"}


   Write-Host "============"
   Write-Host "Processing :"
   $thisMADesc.Value
   if($thisMAID.Value -eq $OldMAID)
   {
      $importChange = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange
      $importChange.Operation = 1
      $importChange.AttributeName = "ConnectedSystem"
      $importChange.AttributeValue = $NewMAID
      $importChange.FullyResolved = 1
      $importChange.Locale = "Invariant"
      $importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
      $importObject.ObjectType = $SyncRule.ResourceManagementObject.ObjectType
      $importObject.TargetObjectIdentifier = $SyncRule.ResourceManagementObject.ObjectIdentifier
 .    $importObject.SourceObjectIdentifier = $SyncRule.ResourceManagementObject.ObjectIdentifier
      $importObject.State = 1 
      $importObject.Changes = (,$importChange)
      write-host " -Writing Synchronization Rule attribute ConnectedSystem = $NewMAID"
      $importObject | Import-FIMConfig -uri $URI -ErrorVariable Err -ErrorAction SilentlyContinue
      if($Err){throw $Err}
      Write-Host "Success!"
   }
 . else
   {
      Write-Host "Referenced MA ID doesn't match, skipping this rule!"
   }

   Write-Host "============"
}
#------------------------------------------------------------------------------------------------------
trap
{ 
   Write-Host "`nError: $($_.Exception.Message)`n" -foregroundcolor white -backgroundcolor darkred
   Exit
}
#------------------------------------------------------------------------------------------------------

 

note Note
To provide feedback about this article, create a post on the FIM TechNet Forum.
For more FIM related Windows PowerShell scripts, see the  FIM ScriptBox

 



See Also