Skip to content

Instantly share code, notes, and snippets.

@KentNordstrom
Last active June 6, 2022 19:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KentNordstrom/0ed7db9ee4f87bd0c6285a30157412b1 to your computer and use it in GitHub Desktop.
Save KentNordstrom/0ed7db9ee4f87bd0c6285a30157412b1 to your computer and use it in GitHub Desktop.
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
@shubhigaur
Copy link

Hi @KentNordstrom
I have a multi-valued attribute that needs to be updated through CSV. The single valued are getting updated as you mentioned, but not the MV, can you suggest the change I need to make in the script to accomplish this. Thanks.

@KentNordstrom
Copy link
Author

Hi @shubhigaur as you can see in the other comments it's not as easy at it looks to make it a "generic" solution. If you have a column with data that needs to go into a MV attribute it will likely be easier to make a version covering your specific scenario.

I have several variants for this depending on the scenario... For example Group.ExplicitMember can be handled from Group perspective adding Persons as members or from Person perspective adding them as members in the listed Group(s).

@shubhigaur
Copy link

Thanks Kent, I made the necessary changes in the script, I will post the script here for reference.

@shubhigaur
Copy link

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)
{
if ($resource.MVattribute -eq $null)
{
($resource.psobject.Properties | ?{$
.Name -eq $Attribute}).Value = ($Object.psobject.Properties | ?{$.Name -eq $Attribute}).Value
}
else
{
$resource.MVattribute.Add(($Object.psobject.Properties | ?{$
.Name -eq $Attribute}).Value)
}
}
$resource | Save-Resource
}

@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