- Download utility script: https://technet.microsoft.com/en-us/library/ff720152(v=ws.10).aspx
- Start with Groups script: https://technet.microsoft.com/en-us/library/ff720141(v=ws.10).aspx
- Change 'Group' to 'Set' and fix script to actually work (see code below).
- Obtain comma-separated values list of persons of interest (hint: use FIM Query Tool)
How to use:
. C:\PS\FIMPowerShell.ps1; . C:\PS\AddMembersToSet.ps1; Import-Csv "C:\PS\PersonsOfInterest.csv" | select 'Resource ID' | % { AddMembersToSet -IdentifierName 'ObjectID' -SetIdentifier '7ee30a29-ca1c-463f-a4ff-0375020b8843' -PersonIdentifiers $_.'Resource ID' -Verbose }
PersonsOfInterest.csv
"Display Name","Account Name","Resource ID" "Garth Maul","GMaul","e330d85f-effd-442b-b78f-d6f7681a44e7" "Sky Walker","SWalker","291959a2-4794-402b-a5f4-f8734326fbe6" "Don Solo","DSolo","e2ae68a9-6b54-43d7-acb8-6b3ed6a82e45"
AddMembersToSet.ps1
$DefaultUri = "http://localhost:5725"function AddMembersToSet{[CmdletBinding()]PARAM($SetIdentifier, $PersonIdentifiers, $IdentifierName="Email", $Uri = $DefaultUri, [switch]$WhatIf)END{Write-Verbose "`$ResolveSet = ResolveObject-ObjectType 'Set' -AttributeName $IdentifierName -AttributeValue$SetIdentifier"$ResolveSet = ResolveObject -ObjectType "Set" -AttributeName $IdentifierName -AttributeValue $SetIdentifier$ResolveSet | Import-FIMConfig -Uri $UriWrite-Verbose "`$ResolveSet: "$ResolveSet$ImportObjects = $NULL$AddedMembers = $NULLforeach($PersonIdentifier in $PersonIdentifiers){Write-Verbose "`$ImportObject = ResolveObject -ObjectType 'Person'-AttributeName $IdentifierName -AttributeValue $PersonIdentifier"$ImportObject = ResolveObject -ObjectType "Person" -AttributeName $IdentifierName -AttributeValue $PersonIdentifier$ImportObject | Import-FIMConfig -Uri $UriWrite-Verbose "`$ImportObject: "$ImportObjectif($AddedMembers -eq $NULL){$AddedMembers = @($ImportObject.SourceObjectIdentifier)}else{$AddedMembers += $ImportObject.SourceObjectIdentifier}if($ImportObjects -eq $NULL){$ImportObjects = @($ImportObject)}else{$ImportObjects += $ImportObject}}$ModifyImportObject = ModifyImportObject -TargetIdentifier $ResolveSet.TargetObjectIdentifier -ObjectType "Set"$ModifyImportObject.SourceObjectIdentifier = $ResolveSet.SourceObjectIdentifierWrite-Verbose "`$ModifyImportObject: "$ModifyImportObjectforeach($AddedMember in $AddedMembers){$newValue = $AddedMember#The followingline adds all of the Person resources to the Set (if not commented out).AddMultiValue -ImportObject $ModifyImportObject -AttributeName "ExplicitMember" -NewAttributeValue $newValue -FullyResolved 0#The followingline removes all of the Person resources from the Set (if not commented out).#RemoveMultiValue-ImportObject $ModifyImportObject -AttributeName "ExplicitMember"-NewAttributeValue $newValue -FullyResolved 0}$ImportObjects += $ModifyImportObjectif (!$WhatIf) {#The following line will update the Setobject with the added members (if not commented out).$ImportObjects | Import-FIMConfig -Uri $Uri#$ImportObjects | % { Import-FIMConfig$_ -Uri $Uri; Break }} else {#The following line returns a referenceto the ImportObject collection (if not commented out).$ImportObjects}}}
No comments:
Post a Comment