Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Bulk update objects in FIM/MIM based on CSV file
Example script to bulk update users from CSV file.
The CSV file needs to have columnnames in row 1.
Columnnames need to correspond to the attribute name in FIM/MIM.
The column specified as "anchor" will not be updated all other columns will be updated based on content in csv file.
Multivalue and Reference data types are not supported in this version.
The script requires that the Lithnet Power Shell module is installed on the computer running the script.
The account running the script requires write permission to all attributes in the csv file except for the anchor attribute.
[string]$CSVFile = 'C:\Temp\CSVUsers.txt',
[string]$Delimiter = ',',
[string]$Anchor = 'AccountName',
[string]$ResourceType = 'Person',
[string]$FIMServiceURI = 'http://localhost:5725'
#region Lithnet
if(!(Get-Module -Name LithnetRMA))
Import-Module LithnetRMA;
Set-ResourceManagementClient -BaseAddress $FIMServiceURI;
#endregion Lithnet
$Objects = Import-Csv -Delimiter $Delimiter -Path $CSVFile
$Attributes = (Get-Content $CSVFile)[0] -split $Delimiter | ?{$_ -ne $Anchor}
ForEach($Object in $Objects)
$resource = Get-Resource -ObjectType $ResourceType -AttributeName $Anchor -AttributeValue ($Object.psobject.Properties | ?{$_.Name -eq $Anchor}).Value -AttributesToGet $Attributes
ForEach ($Attribute in $Attributes)
($resource.psobject.Properties | ?{$_.Name -eq $Attribute}).Value = ($Object.psobject.Properties | ?{$_.Name -eq $Attribute}).Value
$resource | Save-Resource
jdoe,John Doe,1-234-567

KentNordstrom commented Mar 15, 2017

As you can see it does not have any errorhandling in it. I wanted the published version to be as clean as possible to show functionality. Feel free to add comments about what kind of basic errorhandling I should add.


KentNordstrom commented Mar 15, 2017 edited

What would be a good way to handle MultiValue and Reference attributes? Reading the datatype of the attribute I can ask FIMService about it, but what format should we have in the data?

If it is Reference should we then assume it's the same ResourceType and containing the "same" Anchor column/value or should the column name be like #Ref#ResourceType#AnchorAttribute#?

Hi Kent. Flexibility and control of #Anchor#Action#...#RefResourceType#RefAnchorAttribute#RefValue seems right.


For multivalued, I would suspect most would have multivalues in a column therefore something like:


What do you think?


KentNordstrom commented Mar 17, 2017

I agree that for MV values we really need some #Action Add/Remove for Multivalue. Action is not needed for Single Value since "empty" column will be delete of value. So for MV attributes we would get two columns in the CSV something like [#Add#EmailAlias] and [#Remove#EmailAlias]

But if we then combine all and need MV Reference like Group ExplicitMembers we will need some special tagging for #Ref#Type#Anchor.

I will try to come up with some examples and post them here to get feedback. Have made similar script for customers before but they were not as "generic" as I would like this one to be, but at the same time very simple to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment