Public/get-AllegisSnowSchema.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function get-AllegisSnowSchema ($environment, $table, $cred){
    #$table should be 'x_sapo_iiq_connect_sysuser' or 'sys_user'
    $baseurl="https://$environment.service-now.com"
    $user = $cred.UserName
    $pass = $cred.GetNetworkCredential().password
    #$user = "IAMwebservices"
    #$pass = 'n9X0VevWcJlyxY2Y'
    $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')
    $uri="$baseurl/api/now/table/sys_dictionary?sysparm_query=GOTOname=$table"
    #$uri="$baseurl/$($table).do?SCHEMA"
    $response=invoke-WebRequest -Headers $headers -UseBasicParsing -Uri $uri -Method get
    $schema=($response.Content | ConvertFrom-Json).result
    return $schema.element
}