Howto: Update attribute value in FIM using Powershell

Maby you are using a PowerShell Workflow (Like Craig`s here, or Carol`s here) and you want to manipulate an attribute and write it to a attribute on a Person object in FIM.
It`s actually really easy!

Let`s say you are using a simple cmldet to enable a user for Lync 2010:

Enable-CsUser –Identity $UserName –RegistrarPool [LYNCSERVERADR] –SipAddressType EmailAddress

And then just create the SIP address from the same values:

$tempSIP = “sip:$EmailAddress”

Now. You want to write the value of $tempSIP to ex. the Person object`s SIPaddress attribute:

Add-PSSnapin FimAutomation
$ImportState = [Microsoft.ResourceManagement.Automation.ObjectModel.ImportState]
$importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
$importObject.ObjectType = “Person”
$importObject.TargetObjectIdentifier = $objID <- This must be the Person ObjectID
$importObject.SourceObjectIdentifier = $objID <- This must be the Person ObjectID
$importObject.State = $ImportState::Put

$importChange = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange
$importChange.Operation = 1
$importChange.AttributeName = “SIPaddress” <- This is the attribute you want to update in FIM.
$importChange.AttributeValue = $tempSIP <- This is the value you want to write.
$importChange.FullyResolved = 1
$importChange.Locale = “Invariant”
if ($importObject.Changes -eq $null) {$importObject.Changes = (,$importChange)}

Import-FIMConfig -Uri “http://localhost:5725” -ImportObject $importObject

Now. The whole thing can look like this:

Add-PSSnapin FimAutomation
Import-Module lync

Enable-CsUser –Identity $UserName –RegistrarPool [LYNCSERVERADR] –SipAddressType EmailAddress

$tempSIP = “sip:$EmailAddress”

$ImportState = [Microsoft.ResourceManagement.Automation.ObjectModel.ImportState]
$importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
$importObject.ObjectType = “Person”
$importObject.TargetObjectIdentifier = $objID
$importObject.SourceObjectIdentifier = $objID
$importObject.State = $ImportState::Put

$importChange = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange
$importChange.Operation = 1
$importChange.AttributeName = “SIPaddress”
$importChange.AttributeValue = $tempSIP
$importChange.FullyResolved = 1
$importChange.Locale = “Invariant”
if ($importObject.Changes -eq $null) {$importObject.Changes = (,$importChange)}

Import-FIMConfig -Uri “http://localhost:5725” -ImportObject $importObjec

Of course you have to pass the Person`s ObjectID, Username and emailaddress to the script for it to work. But that`s easy with the Function Evaluator 🙂