Public/get-AllegisFIMUser.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function get-AllegisFIMUser ([string]$accountname,[string]$fimservice,[string]$FIMuri='http://localhost:5725/ResourceManagementService',[PSCredential]$fimcred){ if ($fimservice -ne $null){$fimuri="http://$($fimservice):5725/ResourceManagementService"} if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin FIMAutomation} $filter="/Person[AccountName='$accountname']" $command="`$password = ConvertTo-SecureString '$($fimcred.GetNetworkCredential().password)' -AsPlainText -Force `$fimcred = New-Object System.Management.Automation.PSCredential ('$($fimcred.username)', `$password) if(@(get-pssnapin | where-object {`$_.Name -eq `"FIMAutomation`"} ).count -eq 0) {add-pssnapin FIMAutomation} (Export-FIMConfig -Uri $FIMuri -customConfig `"$filter`" -OnlyBaseResources -credential `$fimcred) | convertto-json -depth 100" $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) $user=(& 'powershell.exe' -encodedcommand $encodedCommand) | ConvertFrom-Json return $user } |