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

  • Question

  • 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
     }
    #----------------------------------------------------------------------------------------------------------

    Tuesday, April 14, 2015 6:54 AM

All replies

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


    Regards,
    Manuj Khurana

    Tuesday, April 14, 2015 7:17 AM
  • no am giving the values directly in the powershell command. is there any way i can pull from txt file

    Wednesday, April 15, 2015 5:50 AM
  • 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
    }


    CraigMartin – Edgile, Inc. – http://identitytrench.com

    Wednesday, April 15, 2015 7:23 AM