Public/set-AllegisFIMTGSUser.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
function set-AllegisFIMTGSUser{ [CmdletBinding()] param($objectid,$accountname,[string]$fimservice,[string]$FIMuri='http://localhost:5725/ResourceManagementService',[PSCredential]$fimcred) function CreateObject { <# .SYNOPSIS Creates a new object of type Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject. This object needs to be saved using the SaveObject in order to be commited to the FIMService. Supports pipeline input. .PARAMETER objectType The system name of the FIMService resource type. .EXAMPLE CreateObject -objectType Person .EXAMPLE Objects.Type | CreateObject #> PARAM( [Parameter(ValueFromPipeline=$true)] [string[]]$ObjectType ) BEGIN{} PROCESS { foreach($Type in $ObjectType) { $NewObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject $NewObject.ObjectType = $Type $NewObject.SourceObjectIdentifier = [System.Guid]::NewGuid().ToString() return [Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject]$NewObject } } END{} } function SetAttribute {#Only for SingleValue attributes PARAM([Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject]$ImportObject, [string]$AttributeName, $AttributeValue) END { $ImportChange = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange $ImportChange.Operation = 1 $ImportChange.AttributeName = $AttributeName $ImportChange.AttributeValue = $AttributeValue $ImportChange.FullyResolved = 1 $ImportChange.Locale = "Invariant" if ($ImportObject.Changes -eq $null) {$ImportObject.Changes = (,$ImportChange)} else {$ImportObject.Changes += $ImportChange} } } if ($fimservice -ne $null){$fimuri="http://$($fimservice):5725/ResourceManagementService"} if(@(Get-PSSnapin | Where-Object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {Add-PSSnapin FIMAutomation -ErrorAction SilentlyContinue} $importobject=createobject -ObjectType Person SetAttribute -ImportObject $importObject -AttributeName AccountName -AttributeValue $accountname SetAttribute -ImportObject $importObject -AttributeName TGS_MV -AttributeValue 'true' $importobject.TargetObjectIdentifier=[guid]$objectid $importobject.State=[Microsoft.ResourceManagement.Automation.ObjectModel.ImportState]::Put $importobject.SourceObjectIdentifier=[guid]$objectid Import-FIMConfig -Uri $fimuri -ImportObject $importObject -Credential $fimcred } |