Quantcast
Channel: Forum Microsoft Identity Manager
Viewing all articles
Browse latest Browse all 1783

howto set multiple owners by powershell scripting

$
0
0

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?

 

 


Viewing all articles
Browse latest Browse all 1783

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>