BUY NOW For Sale 70%!
buy viagra

{ }

I’ve just posted this script to the FIM Forum Scriptbox. It helped me do a bulk update of attributes in the FIM Portal that, for various reasons, I didn’t want to export through the Sync Service. I tried to make the script as flexible as possible, so it reads the attribute names from the header row of the CSV. I’ve only tested it wth single-valued string attributes so far.

While developing this script I came across an issue with the Import-FIMConfig cmdlet where it uses a cached copy of the FIM schema (and considering, in retrospect, how long it takes to export the schema, I’m not surprised it does this). If you’ve just added a new attribute to the schema you will need to restart your powershell session. The error I was getting was System.NullReferenceException (forum thread).

Summary

This script will update resources in the FIM Portal using values in a CSV file.

The CSV file must have the following:

  • A header row,
  • The first three columns must be as follows:
    • ObjectType – the resource type name as used in the Portal,
    • IDAttribute – the name of the attribute used to identity the target resource,
    • IDValue – that value of the attribute used to identify the target resource.
  • The remaining columns have the target Attribute Name from the FIM Portal as header.

For example:

ObjectType,IDAttribute,IDValue,Department,JobTitle Person,Email,,IT,Engineer Person,Email,,HR,Advisor

 

Script Code

PARAM($CSVFile,$FIMServer="localhost",$Delimiter=";",$LogFile="ImportCSV-Attributes.log") function GetAttribute { PARAM($exportObject,[string] $name) END { $attribute = $exportObject.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq $name} if ($attribute -ne $null -and $attribute.Value) { $attribute.Value } } } function SetAttribute { PARAM($object, $attributeName, $attributeValue) END { $importChange = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange $importChange.Operation = 1 $importChange.AttributeName = $attributeName $importChange.AttributeValue = $attributeValue $importChange.FullyResolved = 1 $importChange.Locale = "Invariant" if ($object.Changes -eq $null) {$object.Changes = (,$importChange)} else {$object.Changes += $importChange} } } function WriteLog { PARAM($msg) END { Add-Content -Path $LogFile -Encoding ASCII -value $msg write-host $msg } } if (Test-Path $LogFile) {Remove-Item $LogFile} if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin FIMAutomation} $URI = "http://" + $FIMServer + ":5725/ResourceManagementService" # Parse CSV file. Note we're not using import-csv because we don't know what the column headers will be. $csv = Get-Content $CSVFile $header = $csv[0].split($Delimiter) $numcols = $header.length $rowcount = 1 while ($rowcount -lt $csv.length) { $rowvals = $csv[$rowcount].split($Delimiter) $filter = "/" + $rowvals[0] + "[" + $rowvals[1] + "='" + $rowvals[2] + "']" WriteLog -msg "Searching on $filter" $FIMObject = $null $FIMObject = export-fimconfig -uri $URI -customconfig ($filter) -ErrorVariable Err -ErrorAction SilentlyContinue if ($FIMObject.length -gt 1) {$FIMObject = $FIMObject[0]} $FIMObjectID = GetAttribute $FIMObject "ObjectID" $FIMObjectType = GetAttribute $FIMObject "ObjectType" if (($FIMObject -eq $null) -or ($FIMObjectID -eq $null)) { WriteLog -msg " Not found" } else { $bUpdateNeeded = $false # Create Import object that will update object in FIM $importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject $importObject.ObjectType = $FIMObjectType $importObject.TargetObjectIdentifier = $FIMObjectID $importObject.SourceObjectIdentifier = $FIMObjectID $importObject.State = [Microsoft.ResourceManagement.Automation.ObjectModel.ImportState]::Put # Add the attributes $colcount = 3 while ($colcount -lt $rowvals.length) { $currentVal = $null $currentVal = $FIMObject.ResourceManagementObject.ResourceManagementAttributes | where-object {$_.AttributeName -eq $header[$colcount]} if ($rowvals[$colcount].length -eq 0) { $message = " No value to set for " + $header[$colcount] WriteLog -msg $message } elseif (($currentVal -ne $null) -and ($rowvals[$colcount] -eq $currentVal.Value)) { $message = " Value for " + $header[$colcount] + " is already correct" WriteLog -msg $message } else { $bUpdateNeeded = $true $message = " Setting " + $header[$colcount] + " to " + $rowvals[$colcount] WriteLog -msg $message SetAttribute -object $importObject -attributeName $header[$colcount] -attributeValue $rowvals[$colcount] } $colcount += 1 } # Import the changes into FIM if ($bUpdateNeeded) { WriteLog -msg " Importing changes" $importObject | Import-FIMConfig -uri $URI } } $rowcount += 1 }

 

Posted by Carol on . Filed under FIM 2010, powershell. Follow any responses to this post with its comments RSS feed. You can post a comment or trackback from your blog.


Source: http://www.wapshere.com/missmiis/using-powershell-to-update-fim-portal-objects-from-a-csv


BUY NOW For Sale 70%!
buy viagra

Hej Snderborg - Culture, food, events and life on Als, Denmark Imovane 7 5 mg bijsluiter nolvadex

Buy nolvadex online australia shopping Missmiis : Using powershell to update FIM Portal objects from
Buy nolvadex online australia shopping Viagra New Zealand: Erectile Dysfunction Medications Online
Buy nolvadex online australia shopping Buy Post Cycle Therapy Steroids in USA at GetRoids
Buy nolvadex online australia shopping Missmiis : powershell: Retrieving data from Excel
Buy nolvadex online australia shopping T - Steroids for sale online - Buy steroids SHOP
Aromasin (Exemestane Side Effects, Interactions, Warning) Best Four Steroids for Aged People Near 50 Years WhatSteroids Cached Comit Dpartemental de Roller Sports de la Sarthe Dbol Cycle for Beginners (EXPERT GUIDE ) 4-Week
BUY NOW For Sale 70%!
buy viagra