FIM ScriptBox Item

Summary

The objective of this script is to display the configured attribute flow precedence for a specified attribute.
The following screenshot shows a sample output:

There are two methods to get the data from FIM:

Both methods are equally suited to accomplish the task.


Script Code: Using the FIM Synchronization Service

 

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
#---------------------------------------------------------------------------------------------------------------------------------------------------------
 Set-Variable -Name AName  -Value "displayName"
 Set-Variable -name RegKey -Value "hklm:\SYSTEM\CurrentControlSet\Services\FIMSynchronizationService\Parameters" -option constant 
#---------------------------------------------------------------------------------------------------------------------------------------------------------
 Clear-Host
#---------------------------------------------------------------------------------------------------------------------------------------------------------
 if((Test-Path $RegKey) -eq $false)
 {throw (New-Object ExecutionEngineException "FIM registry key not found")}
#---------------------------------------------------------------------------------------------------------------------------------------------------------
 $curFolder     = Split-Path -Parent $MyInvocation.MyCommand.Path
 $tmpFolderName = $curFolder + "\Temp"
 if((Test-Path $tmpFolderName) -eq $true) {remove-item $tmpFolderName -force -recurse}
 New-Item $tmpFolderName -type directory | out-null
#---------------------------------------------------------------------------------------------------------------------------------------------------------
 $tPath = ((Get-ItemProperty "$RegKey").Path) + "Bin\svrexport.exe"
 
 $process = New-Object System.Diagnostics.Process
 $process.StartInfo.Filename = $tPath 
 $process.StartInfo.Arguments = """$tmpFolderName"""
 $process.StartInfo.UseShellExecute = $false 
 $process.StartInfo.RedirectStandardOutput = $true 
 $process.Start() | out-null
 $process.WaitForExit() 

 $myError = $process.StandardOutput.ReadToEnd()
 if($myError.Contains("Error:") -eq $true)
 {throw (new-object ExecutionEngineException $myError.substring($myError.IndexOf('Error:')))}
#---------------------------------------------------------------------------------------------------------------------------------------------------------
 $xmlFile = $tmpFolderName + "\MV.xml"
 $xmlDoc = [xml](Get-Content $xmlFile)
 $nodeList = $xmlDoc.SelectNodes("//import-flows[@mv-attribute=""$AName""]")

 if($nodeList.count -eq 0)
 {
    Write-Host "No matching records found"
    Exit
 }
 else
 {
    Write-Host "Attribute Flow Precedence For $AName :"
    Write-Host " "

    foreach($xmlNode in $nodeList)
    {
       Write-Host $xmlNode.parentNode.SelectSingleNode("@mv-object-type").Value
       Write-Host $xmlNode.SelectSingleNode("@type").Value
       Write-Host " "
    }
 }

 if((Test-Path $tmpFolderName) -eq $true) {remove-item $tmpFolderName -force -recurse}
#---------------------------------------------------------------------------------------------------------------------------------------------------------
 trap 
 { 
    Write-Host $_.Exception.Message -foreground "red"
    Exit
 }
#---------------------------------------------------------------------------------------------------------------------------------------------------------

 


Script Code: Using the FIM Service

 

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
#----------------------------------------------------------------------------------------------------------
 Set-Variable -name URI    -Value "http://fimsrv1:5725/resourcemanagementservice" -Option constant 
 Set-Variable -Name AName  -Value "displayName" -Option constant
#----------------------------------------------------------------------------------------------------------
 If(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin FIMAutomation}
#----------------------------------------------------------------------------------------------------------
 $exportObject = export-fimconfig -uri $URI `
                                  –onlyBaseResources `
                                  -customconfig ("/mv-data")`
                                  -ErrorVariable Err `
                                  -ErrorAction SilentlyContinue 
 If($Err){Throw $Err}
 If($exportObject -eq $null) {throw "Metaverse object not found"}
#----------------------------------------------------------------------------------------------------------
 [xml]$xmlDoc = "<root>" + 
                ($exportObject.ResourceManagementObject.ResourceManagementAttributes | 
                 Where-Object {$_.AttributeName -eq "SyncConfig-import-attribute-flow"}).Value +         
                "</root>"

 $nodeList = $xmlDoc.SelectNodes("//import-flows[@mv-attribute=""$AName""]")
 if($nodeList.count -eq 0)
 {
    Write-Host "No matching records found"
    Exit
 }
 else
 {
    Write-Host "Attribute Flow Precedence For $AName :"
    Write-Host " "

    foreach($xmlNode in $nodeList)
    {
       Write-Host $xmlNode.parentNode.SelectSingleNode("@mv-object-type").Value
       Write-Host $xmlNode.SelectSingleNode("@type").Value
       Write-Host " "
    }
 }
#---------------------------------------------------------------------------------------------------------------------------------------------------------
 Trap 
 { 
    Write-Host $_.Exception.Message -foreground "red"
    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