<#
.SYNOPSIS
    A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
    A longer description of the function, its purpose, common use cases, etc.
.NOTES
    Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
    Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
    Test-MyTestFunction -Verbose
    Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>

function New-ITDServiceNowSession {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [ValidateSet('Production', 'Test', 'Development')]    
        [string]
        $Environment,

        [Parameter(Mandatory=$true)]
        [PSCredential]
        $Credential
    )
    
    begin {
        
    }
    
    process {
        
        switch ($Environment) {
            'Production' {
                $Url = 'https://northdakota.service-now.com'
            }
            'Test' {
                $Url = 'https://northdakotatest.service-now.com'
            }
            'Development' {
                $Url = 'https://northdakotadev.service-now.com'
            }
        }

        $HeaderAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Credential.UserName, $Credential.GetNetworkCredential().Password)))
        $SNOWSessionHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
        $SNOWSessionHeader.Add('Authorization', ('Basic {0}' -f $HeaderAuth))
        $SNOWSessionHeader.Add('Accept', 'application/json')
        $ContentType = "application/json"

        $NewSession = @{
            Uri = $Url;
            Headers = $SNOWSessionHeader;
            ContentType = $ContentType;
        }
        
        $Script:ServiceNowSession = $newSession
    }
    
    end {
        
    }
}

<#   
    $HeaderAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $SNowVMCred.UserName, $SNowVMCred.GetNetworkCredential().Password)))
    $SNOWSessionHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $SNOWSessionHeader.Add('Authorization', ('Basic {0}' -f $HeaderAuth))
    $SNOWSessionHeader.Add('Accept', 'application/json')
    $ContentType = "application/json"
#>