howto set multiple owners by powershell scripting
So I have learned it is possible to set multiple Owners, but only one DisplayedOwner and would like to set the owners from a CSV file. The script I have created works just fine with only one owner/displayedowner, but if I try to set two owners in the csv by semicolon seperating the values it fails. This is my script: if (@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) { Add-PSSnapIn FIMAutomation } function CreateImportChange { PARAM($AttributeName, $AttributeValue, $Operation) END { $importChange = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange $importChange.Operation = $Operation $importChange.AttributeName = $AttributeName $importChange.AttributeValue = $AttributeValue $importChange.FullyResolved = 0 $importChange.Locale = "Invariant" return $importChange } } $csv = Import-Csv -header "GroupName","Owner","DispOwner" "c:\temp\mailbox2.csv" foreach ($entry in $csv) { $myGroupName=$entry.GroupName $myOwner=$entry.Owner $myDispOwner=$entry.DispOwner $uri="http://ivabfim01:5725/resourcemanagementservice" # Get Owner $ownerObject = export-fimconfig -uri $URI ` onlyBaseResources ` -customconfig "/Person[AccountName='$myOwner']" if($ownerObject -eq $null) {Write-Host -ForeGroundcolor Red "Owner not found! (Group: $myGroupName - Owner: $myOwner)"} else{ $ownerID = $ownerObject.ResourceManagementObject.ObjectIdentifier -replace "urn:uuid:","" # Get DisplayedOwner $DispownerObject = export-fimconfig -uri $URI ` onlyBaseResources ` -customconfig "/Person[AccountName='$myDispOwner']" if($DispownerObject -eq $null) {Write-Host -ForegroundColor Red "DisplayedOwner not found! (Group: $myGroupName - Owner: $myOwner)"} else{ $DispownerID = $DispownerObject.ResourceManagementObject.ObjectIdentifier -replace "urn:uuid:","" #uncomment to verify the connection to the csv file is working and correct output. #Write-Host Group: $myGroupName Owner: $myOwner($ownerID) DisplayedOwner: $myDispOwner($DispownerID) $group = Export-FIMConfig -uri "$uri" -customConfig "/Group[AccountName='$myGroupName']" -onlyBaseResources if ($group -eq $NULL) {Write-Host -ForegroundColor Red "Group Does not exist! Skipping...(Group: $myGroupName - Owner: $myOwner)"} else{ #construct the web service operation $importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject #the object type is Group $importObject.ObjectType = "Group" #we are modify the group we've identified above $importObject.SourceObjectIdentifier = $group.ResourceManagementObject.ObjectIdentifier $importObject.TargetObjectIdentifier = $group.ResourceManagementObject.ObjectIdentifier #Put operation is enum 1 $importObject.State = 1 #construct the operation to Replace filter, Replace attribute operation is enum 1 $importObject.Changes += CreateImportChange -attributeName "Owner" -attributeValue $ownerID -Operation 0 $importObject.Changes += CreateImportChange -attributeName "DisplayedOwner" -attributeValue $DispownerID -Operation 1 $importObject | Import-FIMConfig -Uri "$uri"} } } } This is the input from the csv file: FIM_Mailbox_TestMail-SEC,Nico,Nico FIM_Mailbox_TestMail2-SEC,Nico;Nico2,Nico The script stops at the error: Owner not found! (Group: FIM_Mailbox_TestMail2-SEC Owner: Nico;Nico2) Anybody with an idea how to resolve multiple users and able to set them as owner?
January 25th, 2011 3:59pm

Looking at your code, I see where the display name of the owner is converted into it's real value. What it looks like you need to do is to break the array of owners up and convert each one. Not sure if they can be reasembled into one update value, or if you have to run the CreateResourceChange function for each owner value. Try it out and let us know
Free Windows Admin Tool Kit Click here and download it now
January 25th, 2011 10:08pm

Nicolai I believe Frank is correct; your function that extracts owner interprets the value 'nico, nico2' as one object and of course it can't find it so it says that this object doesn't exist. As Frank states, you need to look in the value for a delimitter characters, such as ','. You can use this to split the entry into multiple values and add each of them as owner. Glenn
January 25th, 2011 11:56pm

Nicolai I believe Frank is correct; your function that extracts owner interprets the value 'nico, nico2' as one object and of course it can't find it so it says that this object doesn't exist. As Frank states, you need to look in the value for a delimitter characters, such as ','. You can use this to split the entry into multiple values and add each of them as owner. Glenn
Free Windows Admin Tool Kit Click here and download it now
January 25th, 2011 11:56pm

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

Other recent topics Other recent topics