How to create bulk user ids in the FIM 2010 using powershell

i have the below powershell script but which will create only one user at time in the FIM. Can somebody help me with powershell scripit which will help us to create a bulk users .

#----------------------------------------------------------------------------------------------------------
 set-variable -name URI -value "http://localhost:5725/resourcemanagementservice' " -option constant
#----------------------------------------------------------------------------------------------------------
 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 CreateObject
 {
    PARAM($objectType)
    END
    {
       $newObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
       $newObject.ObjectType = $objectType
       $newObject.SourceObjectIdentifier = [System.Guid]::NewGuid().ToString()
       $newObject
     }
 }
#----------------------------------------------------------------------------------------------------------
 if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin FIMAutomation}
 clear-host

 if($args.count -ne 1) {throw "You need to specify your attribute values as parameter"}
 $attributes = ($args[0]).split("|")

 if(0 -ne [String]::Compare(($attributes[0]).split(":")[0],"displayname", $true))
 {throw "You need to specify a display name"}

 $objectName = ($attributes[0]).split(":")[1]
 $exportObject = export-fimconfig -uri $URI `
                                  onlyBaseResources `
                                  -customconfig "/Person[DisplayName='$objectName']"
 if($exportObject) {throw "L:User $objectName already exists"}

 $newUser = CreateObject -objectType "Person"
 foreach($attribute in $attributes)
 {
    $attrData = $attribute.split(":")
    SetAttribute -object $newUser `
                 -attributeName  $($attrData[0]) `
                 -attributeValue $($attrData[1])
 }             

 $newUser | Import-FIMConfig -uri $URI
 write-host "`nUser created successfully`n"
#----------------------------------------------------------------------------------------------------------
 trap
 {
    $exMessage = $_.Exception.Message
    if($exMessage.StartsWith("L:"))
    {write-host "`n" $exMessage.substring(2) "`n" -foregroundcolor white -backgroundcolor darkblue}
    else {write-host "`nError: " $exMessage "`n" -foregroundcolor white -backgroundcolor darkred}
    Exit
 }
#----------------------------------------------------------------------------------------------------------

April 14th, 2015 2:56am

Are you using any notepad to pull in the values? Or you are giving the value of the attributes directly in the Powershell Command?

Free Windows Admin Tool Kit Click here and download it now
April 14th, 2015 3:19am

no am giving the values directly in the powershell command. is there any way i can pull from txt file

April 15th, 2015 1:52am

There's a good example on the FIM PowerShell Module CodePlex site.

You could extend it by doing something like this:

### Create a sample CSV file
@'
FirstName, LastName, AccountName, DisplayName
James, Bond, JamesBond, Agent
James, Taylor, JamesTaylor, Quartet
Wayne, Gretzky, WayneGretzky, The One
'@ | Out-File -FilePath Users.csv

### Create the users in FIM 
foreach ($user in Import-Csv -Path Users.csv)
{
    New-FimImportObject -ObjectType Person -State Create -Changes @{
       DisplayName  = $user.DisplayName
       AccountName  = $user.AccountName
       FirstName    = $user.FirstName
       LastName     = $user.LastName
       Description  = 'Have any grapes?'
       EmployeeType = 'Contractor'
       Domain       = 'LITWARE'
       Email        = "$($user.AccountName)@litware.ca"
    } -ApplyNow
}

Free Windows Admin Tool Kit Click here and download it now
April 15th, 2015 3:25am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics