-
-
Save KentNordstrom/0ed7db9ee4f87bd0c6285a30157412b1 to your computer and use it in GitHub Desktop.
| <# | |
| .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 |
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 (
ForEach ($Attribute in $Attributes)
{
if ($resource.MVattribute -eq $null)
{
($resource.psobject.Properties | ?{$.Name -eq $Attribute}).Value = (
}
else
{
$resource.MVattribute.Add(($Object.psobject.Properties | ?{$.Name -eq $Attribute}).Value)
}
}
$resource | Save-Resource
}
@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.
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
Thanks Kent, I made the necessary changes in the script, I will post the script here for reference.