Public/get-AllegisSNOWUsers.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function get-AllegisSNOWUsers{
Param(
    [string]$snowFilter,
    [string]$snowOrg,
    [pscredential]$snowcred,    
    [string]$snowEnv
)
    $method = 'get'
    $uri = "https://$snowOrg.service-now.com/api/now/table/sys_user?sysparm_query=$snowfilter&sysparm_display_value=true"
    $command="`$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((""{0}:{1}"" -f '$($snowcred.username)', '$($snowcred.getnetworkcredential().password)')))
    `$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-preview\pwsh.exe' -encodedcommand $encodedCommand
    $json=$results | ConvertFrom-Json
    return $json
}