Public/get-AllegisSnowUser.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function get-AllegisSnowUser ([string]$snowenv, [pscredential]$snowcred, [string]$uid) { $snowFilter="u_nick_name=$uid^ORemailSTARTSWITH$uid@^ORuser_nameSTARTSWITH$uid@" $snowtable='sys_user' $user = $snowcred.username $pass = $snowcred.GetNetworkCredential().password $method = 'get' $uri = "https://$snowEnv.service-now.com/api/now/table/$($snowtable)?sysparm_query=$snowfilter&sysparm_limit=$limit" $command="`$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((""{0}:{1}"" -f '$user', '$pass'))) `$headers = New-Object ""System.Collections.Generic.Dictionary[[String],[String]]"" `$headers.Add('Authorization',('Basic {0}' -f `$base64AuthInfo)) `$headers.Add('Accept','application/json') `$response=Invoke-RestMethod -Headers `$headers -Method '$method' -Uri '$uri' -UseBasicParsing -FollowRelLink #-MaximumFollowRelLink 2 return `$response.result | convertto-json " $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) $results=& 'C:\Program Files\PowerShell\6\pwsh.exe' -encodedcommand $encodedCommand $json=$results | convertfrom-json return $json } |