@@ -57,15 +57,20 @@ function Get-ServiceNowTable {
5757 # Get credential and ServiceNow REST URL
5858 if ($null -ne $Connection ) {
5959 $SecurePassword = ConvertTo-SecureString $Connection.Password - AsPlainText - Force
60- $ServiceNowCredential = New-Object System.Management.Automation.PSCredential ($Connection.Username , $SecurePassword )
60+ $Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username , $SecurePassword )
6161 $ServiceNowURL = ' https://' + $Connection.ServiceNowUri + ' /api/now/v1'
6262 }
63- elseif ($null -ne $ServiceNowCredential -and $null -ne $ServiceNowURL ) {
64- Test-ServiceNowURL - Url $ServiceNowURL
65- $ServiceNowURL = ' https://' + $ServiceNowURL + ' /api/now/v1'
63+ elseif ($null -ne $Credential -and $null -ne $ServiceNowURL ) {
64+ Try {
65+ $null = Test-ServiceNowURL - Url $ServiceNowURL - ErrorAction Stop
66+ $ServiceNowURL = ' https://' + $ServiceNowURL + ' /api/now/v1'
67+ }
68+ Catch {
69+ Throw $PSItem
70+ }
6671 }
6772 elseif ((Test-ServiceNowAuthIsSet )) {
68- $ServiceNowCredential = $Global :ServiceNowCredentials
73+ $Credential = $Global :ServiceNowCredentials
6974 $ServiceNowURL = $global :ServiceNowRESTURL
7075 }
7176 else {
@@ -124,7 +129,7 @@ function Get-ServiceNowTable {
124129
125130 # Perform table query and capture results
126131 $Uri = $ServiceNowURL + " /table/$Table "
127- $Result = (Invoke-RestMethod - Uri $Uri - Credential $ServiceNowCredential - Body $Body - ContentType " application/json" ).Result
132+ $Result = (Invoke-RestMethod - Uri $Uri - Credential $Credential - Body $Body - ContentType " application/json" ).Result
128133
129134 # Convert specific fields to DateTime format
130135 $ConvertToDateField = @ (' closed_at' , ' expected_start' , ' follow_up' , ' opened_at' , ' sys_created_on' , ' sys_updated_on' , ' work_end' , ' work_start' )
0 commit comments