Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bulk update objects in FIM/MIM based on CSV file
<#
.SYNOPSIS
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.
#>
PARAM(
[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
}
AccountName,DisplayName,OfficePhone
jdoe,John Doe,1-234-567
@KentNordstrom
Copy link
Author

@shubhigaur Do you have a small sample csv file that works with your version of the script? Just for reference if people find this Gist.

@shubhigaur
Copy link

ADDN:OUMapping
OU=00001,OU=Branches,DC=LO,DC=AD,DC=UAT:Oxford Branch
OU=00002,OU=Branches,DC=LO,DC=AD,DC=UAT:ABCD Branch
OU=00003,OU=Branches,DC=LO,DC=AD,DC=UAT:MI Branch
OU=00003,OU=Branches,DC=LO,DC=AD,DC=UAT:COD Branch
OU=00004,OU=Branches,DC=LO,DC=AD,DC=UAT:NO Branch
OU=00004,OU=Branches,DC=LO,DC=AD,DC=UAT:CSO Branch

I am mapping ADDN with a branch name here. 00003 and 0004 has multiple values and OUMapping is a MV attribute here

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