How do I add a user to a set

 

So over the past month, I get the same question How do I add a user to a set / aka admin set?

This can be simply done with the FIMAutomation

 

image

[code language=”powershell”]

Script Below :

#——————————————————————————————————————–
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$set,
[Parameter(Mandatory=$True)]
[string]$username,
[Parameter(Mandatory=$True)]
[string]$url

)

$URI = "http://" + $url + ":5725/resourcemanagementservice"
Write-Progress $SET
Write-Progress $USERNAME
Write-Progress $URI
#——————————————————————————————————————–
Function GetSingleResource
{
Param($Filter)
End
{
$exportResource = export-fimconfig -uri $URI `
–onlyBaseResources `
-customconfig ("$Filter")`
-ErrorVariable Err `
-ErrorAction SilentlyContinue
If($Err){Throw $Err}
If($exportResource -eq $null) {Throw "Resource not found: $Filter"}
If(@($exportResource).Count -ne 1) {Throw "More than one resource found: $Filter"}
$exportResource
}
}
#——————————————————————————————————————–
If(@(Get-PSSnapin | Where-Object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {Add-PSSnapin FIMAutomation}
Clear-Host
$ProgressPreference = "SilentlyContinue"
#——————————————————————————————————————–
$ProgressPreference = "Continue"
Write-Progress -Activity "Retrieving set object" `
-Status "Please wait…" `
-CurrentOperation "Processing step 1 of 3"
$ProgressPreference = "SilentlyContinue"
$setObject = GetSingleResource -Filter "/Set[DisplayName=’$SET’]"

$ProgressPreference = "Continue"
Write-Progress -Activity "Retrieving user object" `
-Status "Please wait…" `
-CurrentOperation "Processing step 2 of 3"
$ProgressPreference = "SilentlyContinue"
$userObject = GetSingleResource -Filter "/Person[DisplayName=’$USERNAME’]"

$importChange = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange
$importChange.Operation = 0
$importChange.AttributeName = "ExplicitMember"
$importChange.AttributeValue = $userObject.ResourceManagementObject.ObjectIdentifier
$importChange.FullyResolved = 0
$importChange.Locale = "Invariant"

$importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
$importObject.ObjectType = "Set"
$importObject.TargetObjectIdentifier = $setObject.ResourceManagementObject.ObjectIdentifier
$importObject.SourceObjectIdentifier = $setObject.ResourceManagementObject.ObjectIdentifier
$importObject.State = 1
$ImportObject.Changes = (,$ImportChange)

$ProgressPreference = "Continue"
Write-Progress -Activity "Adding user to set" `
-Status "Please wait…" `
-CurrentOperation "Processing step 3 of 3"
$ProgressPreference = "SilentlyContinue"

$importObject | Import-FIMConfig -Uri $URI -ErrorVariable Err -ErrorAction SilentlyContinue | Out-Null
If($Err){Throw $Err}
#——————————————————————————————————————–
Write-Host "Command completed successfully"
#——————————————————————————————————————–
Trap
{
Write-Host $_.Exception.Message -foregroundcolor white -backgroundcolor darkred
Write-Host $_.Exception.GetType().FullName -foregroundcolor white -backgroundcolor darkred
Write-Host "`n"
Exit 1
}
#——————————————————————————————————————–

[/code]

 


David Steadman has written 39 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>