none
Change a Users custom Attribute Value in powershell

    Question

  • Hello everyone,

     

    i was wondering if i could set the value of a custom attribute a created and added to the users' portal through a powershell script

    the idea is to simplify the porcess for my hr people instead of having them login and set it manually


    Hitch Bardawil
    Monday, July 25, 2011 7:55 AM

Answers

  • 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 GetObject
    {
     PARAM($objectType,$objectid)
     END
     {
     $importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
     $importObject.ObjectType = $objectType
     $importObject.TargetObjectIdentifier = $objectid
     $importObject.SourceObjectIdentifier = $objectid
     $importObject.State = [Microsoft.ResourceManagement.Automation.ObjectModel.ImportState]::Put
    return $importObject
     } } if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"}).count -eq 0){add-pssnapin "FIMAutomation"} $users = export-FIMConfig -CustomConfig "/Person" –onlyBaseResources -Uri "http://localhost:5725" foreach($user in $users) { $obj = GetObject -objectType "Person" -objectid ($user.ResourceManagementObject.ObjectIdentifier) SetAttribute -object $obj -attributeName "your attribute name" -attributeValue "your attribute value" $obj | Import-FIMConfig -uri "http://localhost:5725" } write-host "Success" #------------------------------------------------------------------------------------------------------ trap { Write-Host "`nError: $($_.Exception.Message)`n" -foregroundcolor white -backgroundcolor darkred Exit } #------------------------------------------------------------------------------------------------------

     

     

    you can even get the values from csv file refer to this:

    http://www.wapshere.com/missmiis/using-powershell-to-update-fim-portal-objects-from-a-csv


    It's never too late in life ... to start living



    • Marked as answer by HitchB52 Monday, July 25, 2011 2:59 PM
    • Edited by Amer Almotlaq Monday, July 25, 2011 4:48 PM
    Monday, July 25, 2011 10:17 AM

All replies

  • 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 GetObject
    {
     PARAM($objectType,$objectid)
     END
     {
     $importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
     $importObject.ObjectType = $objectType
     $importObject.TargetObjectIdentifier = $objectid
     $importObject.SourceObjectIdentifier = $objectid
     $importObject.State = [Microsoft.ResourceManagement.Automation.ObjectModel.ImportState]::Put
    return $importObject
     } } if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"}).count -eq 0){add-pssnapin "FIMAutomation"} $users = export-FIMConfig -CustomConfig "/Person" –onlyBaseResources -Uri "http://localhost:5725" foreach($user in $users) { $obj = GetObject -objectType "Person" -objectid ($user.ResourceManagementObject.ObjectIdentifier) SetAttribute -object $obj -attributeName "your attribute name" -attributeValue "your attribute value" $obj | Import-FIMConfig -uri "http://localhost:5725" } write-host "Success" #------------------------------------------------------------------------------------------------------ trap { Write-Host "`nError: $($_.Exception.Message)`n" -foregroundcolor white -backgroundcolor darkred Exit } #------------------------------------------------------------------------------------------------------

     

     

    you can even get the values from csv file refer to this:

    http://www.wapshere.com/missmiis/using-powershell-to-update-fim-portal-objects-from-a-csv


    It's never too late in life ... to start living



    • Marked as answer by HitchB52 Monday, July 25, 2011 2:59 PM
    • Edited by Amer Almotlaq Monday, July 25, 2011 4:48 PM
    Monday, July 25, 2011 10:17 AM
  • A great place to start for this kind of questions is the FIM ScriptBox. In it's current form it's available as "How to" Wiki Articles. Check "FIM How To Script" for a complete overview: FIM 2010 Wiki Articles

    And the article referenced by Amer: How to Use PowerShell to Update Resources from a CSV File [Carol Wapshere]

    And as a general framework to perform operations on FIM Portal objects: How to Use PowerShell as a FIM Function Library [_Work In Progress_]


    http://setspn.blogspot.com
    Monday, July 25, 2011 12:07 PM
  • thanks guyz
    Hitch Bardawil
    Monday, July 25, 2011 2:59 PM