Skip to content

Commit 11162c9

Browse files
committed
Reversed most of #26 after testing
1 parent 89a5c2d commit 11162c9

File tree

7 files changed

+85
-100
lines changed

7 files changed

+85
-100
lines changed

ServiceNow/Public/Get-ServiceNowChangeRequest.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Get-ServiceNowChangeRequest {
66
[parameter(ParameterSetName='UseConnectionObject')]
77
[parameter(ParameterSetName='SetGlobalAuth')]
88
[string]$OrderBy='opened_at',
9-
9+
1010
# Direction of ordering (Desc/Asc)
1111
[parameter(mandatory=$false)]
1212
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -21,7 +21,7 @@ function Get-ServiceNowChangeRequest {
2121
[parameter(ParameterSetName='UseConnectionObject')]
2222
[parameter(ParameterSetName='SetGlobalAuth')]
2323
[int]$Limit=10,
24-
24+
2525
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
2626
[parameter(mandatory=$false)]
2727
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -42,24 +42,24 @@ function Get-ServiceNowChangeRequest {
4242
[parameter(ParameterSetName='UseConnectionObject')]
4343
[parameter(ParameterSetName='SetGlobalAuth')]
4444
[ValidateSet("true","false", "all")]
45-
[string]$DisplayValues='false',
45+
[string]$DisplayValues='true',
4646

4747
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
4848
[ValidateNotNullOrEmpty()]
4949
[PSCredential]
50-
$ServiceNowCredential,
50+
$ServiceNowCredential,
5151

5252
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
5353
[ValidateNotNullOrEmpty()]
5454
[string]
55-
$ServiceNowURL,
55+
$ServiceNowURL,
5656

57-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
57+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
5858
[ValidateNotNullOrEmpty()]
5959
[Hashtable]
6060
$Connection
6161
)
62-
62+
6363
# Query Splat
6464
$newServiceNowQuerySplat = @{
6565
OrderBy = $OrderBy
@@ -68,7 +68,7 @@ function Get-ServiceNowChangeRequest {
6868
MatchContains = $MatchContains
6969
}
7070
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
71-
71+
7272
# Table Splat
7373
$getServiceNowTableSplat = @{
7474
Table = 'change_request'
@@ -79,10 +79,10 @@ function Get-ServiceNowChangeRequest {
7979

8080
# Update the Table Splat if the parameters have values
8181
if ($null -ne $PSBoundParameters.Connection)
82-
{
82+
{
8383
$getServiceNowTableSplat.Add('Connection',$Connection)
8484
}
85-
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
85+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
8686
{
8787
$getServiceNowTableSplat.Add('ServiceNowCredential',$ServiceNowCredential)
8888
$getServiceNowTableSplat.Add('ServiceNowURL',$ServiceNowURL)
@@ -92,4 +92,4 @@ function Get-ServiceNowChangeRequest {
9292
$Result = Get-ServiceNowTable @getServiceNowTableSplat
9393
$Result | ForEach-Object{$_.PSObject.TypeNames.Insert(0,"ServiceNow.ChangeRequest")}
9494
$Result
95-
}
95+
}

ServiceNow/Public/Get-ServiceNowConfigurationItem.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Get-ServiceNowConfigurationItem {
66
[parameter(ParameterSetName='UseConnectionObject')]
77
[parameter(ParameterSetName='SetGlobalAuth')]
88
[string]$OrderBy='name',
9-
9+
1010
# Direction of ordering (Desc/Asc)
1111
[parameter(mandatory=$false)]
1212
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -21,7 +21,7 @@ function Get-ServiceNowConfigurationItem {
2121
[parameter(ParameterSetName='UseConnectionObject')]
2222
[parameter(ParameterSetName='SetGlobalAuth')]
2323
[int]$Limit=10,
24-
24+
2525
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
2626
[parameter(mandatory=$false)]
2727
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -42,19 +42,19 @@ function Get-ServiceNowConfigurationItem {
4242
[parameter(ParameterSetName='UseConnectionObject')]
4343
[parameter(ParameterSetName='SetGlobalAuth')]
4444
[ValidateSet("true","false", "all")]
45-
[string]$DisplayValues='false',
45+
[string]$DisplayValues='true',
4646

4747
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
4848
[ValidateNotNullOrEmpty()]
4949
[PSCredential]
50-
$ServiceNowCredential,
50+
$ServiceNowCredential,
5151

5252
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
5353
[ValidateNotNullOrEmpty()]
5454
[string]
55-
$ServiceNowURL,
55+
$ServiceNowURL,
5656

57-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
57+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
5858
[ValidateNotNullOrEmpty()]
5959
[Hashtable]
6060
$Connection
@@ -68,7 +68,7 @@ function Get-ServiceNowConfigurationItem {
6868
MatchContains = $MatchContains
6969
}
7070
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
71-
71+
7272
# Table Splat
7373
$getServiceNowTableSplat = @{
7474
Table = 'cmdb_ci'
@@ -79,10 +79,10 @@ function Get-ServiceNowConfigurationItem {
7979

8080
# Update the Table Splat if the parameters have values
8181
if ($null -ne $PSBoundParameters.Connection)
82-
{
82+
{
8383
$getServiceNowTableSplat.Add('Connection',$Connection)
8484
}
85-
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
85+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
8686
{
8787
$getServiceNowTableSplat.Add('ServiceNowCredential',$ServiceNowCredential)
8888
$getServiceNowTableSplat.Add('ServiceNowURL',$ServiceNowURL)

ServiceNow/Public/Get-ServiceNowIncident.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Get-ServiceNowIncident{
66
[parameter(ParameterSetName='UseConnectionObject')]
77
[parameter(ParameterSetName='SetGlobalAuth')]
88
[string]$OrderBy='opened_at',
9-
9+
1010
# Direction of ordering (Desc/Asc)
1111
[parameter(mandatory=$false)]
1212
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -21,7 +21,7 @@ function Get-ServiceNowIncident{
2121
[parameter(ParameterSetName='UseConnectionObject')]
2222
[parameter(ParameterSetName='SetGlobalAuth')]
2323
[int]$Limit=10,
24-
24+
2525
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
2626
[parameter(mandatory=$false)]
2727
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -42,22 +42,22 @@ function Get-ServiceNowIncident{
4242
[parameter(ParameterSetName='UseConnectionObject')]
4343
[parameter(ParameterSetName='SetGlobalAuth')]
4444
[ValidateSet("true","false", "all")]
45-
[string]$DisplayValues='false',
45+
[string]$DisplayValues='true',
4646

47-
# Credential used to authenticate to ServiceNow
47+
# Credential used to authenticate to ServiceNow
4848
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
4949
[ValidateNotNullOrEmpty()]
5050
[PSCredential]
51-
$ServiceNowCredential,
51+
$ServiceNowCredential,
5252

53-
# The URL for the ServiceNow instance being used
53+
# The URL for the ServiceNow instance being used
5454
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
5555
[ValidateNotNullOrEmpty()]
5656
[string]
57-
$ServiceNowURL,
57+
$ServiceNowURL,
5858

5959
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
60-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
60+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
6161
[ValidateNotNullOrEmpty()]
6262
[Hashtable]
6363
$Connection
@@ -72,20 +72,20 @@ function Get-ServiceNowIncident{
7272
}
7373
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
7474

75-
# Table Splat
75+
# Table Splat
7676
$getServiceNowTableSplat = @{
7777
Table = 'incident'
7878
Query = $Query
7979
Limit = $Limit
8080
DisplayValues = $DisplayValues
8181
}
82-
82+
8383
# Update the splat if the parameters have values
8484
if ($null -ne $PSBoundParameters.Connection)
85-
{
85+
{
8686
$getServiceNowTableSplat.Add('Connection',$Connection)
8787
}
88-
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
88+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
8989
{
9090
$getServiceNowTableSplat.Add('ServiceNowCredential',$ServiceNowCredential)
9191
$getServiceNowTableSplat.Add('ServiceNowURL',$ServiceNowURL)

ServiceNow/Public/Get-ServiceNowTable.ps1

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
function Get-ServiceNowTable {
22
<#
3-
.SYNOPSIS
4-
Retrieves multiple records for the specified table
5-
.DESCRIPTION
6-
The Get-ServiceNowTable function retrieves multiple records for the specified table
7-
.INPUTS
8-
None
9-
.OUTPUTS
10-
System.Management.Automation.PSCustomObject
11-
.LINK
12-
Service-Now Kingston REST Table API: https://docs.servicenow.com/bundle/kingston-application-development/page/integrate/inbound-rest/concept/c_TableAPI.html
13-
Service-Now Table API FAQ: https://hi.service-now.com/kb_view.do?sysparm_article=KB0534905
3+
.SYNOPSIS
4+
Retrieves records for the specified table
5+
.DESCRIPTION
6+
The Get-ServiceNowTable function retrieves records for the specified table
7+
.INPUTS
8+
None
9+
.OUTPUTS
10+
System.Management.Automation.PSCustomObject
11+
.LINK
12+
Service-Now Kingston REST Table API: https://docs.servicenow.com/bundle/kingston-application-development/page/integrate/inbound-rest/concept/c_TableAPI.html
13+
Service-Now Table API FAQ: https://hi.service-now.com/kb_view.do?sysparm_article=KB0534905
1414
#>
15-
[OutputType([Array])]
15+
16+
[OutputType([System.Management.Automation.PSCustomObject])]
1617
Param (
1718
# Name of the table we're querying (e.g. incidents)
1819
[parameter(Mandatory)]
@@ -34,12 +35,12 @@ function Get-ServiceNowTable {
3435
[parameter(ParameterSetName = 'SetGlobalAuth')]
3536
[int]$Limit = 10,
3637

37-
# Whether to return manipulated display values rather than actual database values.
38+
# Whether or not to show human readable display values instead of machine values
3839
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
3940
[parameter(ParameterSetName = 'UseConnectionObject')]
4041
[parameter(ParameterSetName = 'SetGlobalAuth')]
4142
[ValidateSet("true", "false", "all")]
42-
[string]$DisplayValues = 'false',
43+
[string]$DisplayValues = 'true',
4344

4445
# Credential used to authenticate to ServiceNow
4546
[Parameter(ParameterSetName = 'SpecifyConnectionFields')]
@@ -72,7 +73,6 @@ function Get-ServiceNowTable {
7273
elseif ((Test-ServiceNowAuthIsSet)) {
7374
$ServiceNowCredential = $Global:ServiceNowCredentials
7475
$ServiceNowURL = $global:ServiceNowRESTURL
75-
$ServiceNowDateFormat = $Global:ServiceNowDateFormat
7676
}
7777
else {
7878
throw "Exception: You must do one of the following to authenticate: `n 1. Call the Set-ServiceNowAuth cmdlet `n 2. Pass in an Azure Automation connection object `n 3. Pass in an endpoint and credential"
@@ -89,27 +89,28 @@ function Get-ServiceNowTable {
8989
$Result = (Invoke-RestMethod -Uri $Uri -Credential $ServiceNowCredential -Body $Body -ContentType "application/json").Result
9090

9191
# Convert specific fields to DateTime format
92-
$DefaultServiceNowDateFormat = 'yyyy-MM-dd HH:mm:ss'
9392
$ConvertToDateField = @('closed_at', 'expected_start', 'follow_up', 'opened_at', 'sys_created_on', 'sys_updated_on', 'work_end', 'work_start')
9493
ForEach ($SNResult in $Result) {
9594
ForEach ($Property in $ConvertToDateField) {
9695
If (-not [string]::IsNullOrEmpty($SNResult.$Property)) {
97-
If ($DisplayValues -eq $True) {
98-
# DateTime fields returned in the Service-Now instance system date format need converting to the local computers "culture" setting based upon the format specified
96+
Try {
97+
# Extract the default Date/Time formatting from the local computer's "Culture" settings, and then create the format to use when parsing the date/time from Service-Now
98+
$CultureDateTimeFormat = (Get-Culture).DateTimeFormat
99+
$DateFormat = $CultureDateTimeFormat.ShortDatePattern
100+
$TimeFormat = $CultureDateTimeFormat.LongTimePattern
101+
$DateTimeFormat = "$DateFormat $TimeFormat"
102+
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $DateTimeFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo, [System.Globalization.DateTimeStyles]::None)
103+
}
104+
Catch {
99105
Try {
100-
Write-Debug "Date Parsing field: $Property, value: $($SNResult.$Property) against global format $Global:ServiceNowDateFormat"
101-
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $Global:ServiceNowDateFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo)
106+
# Universal Format
107+
$DateTimeFormat = 'yyyy-MM-dd HH:mm:ss'
108+
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $DateTimeFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo, [System.Globalization.DateTimeStyles]::None)
102109
}
103110
Catch {
104-
Throw "Problem parsing date-time field $Property with value $($SNResult.$Property) against format $Global:ServiceNowDateFormat. " +
105-
"Please verify the DateFormat parameter matches the glide.sys.date_format property of the Service-Now instance"
111+
# If the local culture and universal formats both fail keep the property as a string (Do nothing)
106112
}
107113
}
108-
Else {
109-
# DateTime fields always returned as yyyy-MM-dd hh:mm:ss when sysparm_display_value is set to false
110-
Write-Debug "Date Parsing field: $Property, value: $($SNResult.$Property) against default format $DefaultServiceNowDateFormat"
111-
$SNResult.$Property = [DateTime]::ParseExact($($SNResult.$Property), $DefaultServiceNowDateFormat, [System.Globalization.DateTimeFormatInfo]::InvariantInfo)
112-
}
113114
}
114115
}
115116
}

ServiceNow/Public/Get-ServiceNowUser.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Get-ServiceNowUser{
66
[parameter(ParameterSetName='UseConnectionObject')]
77
[parameter(ParameterSetName='SetGlobalAuth')]
88
[string]$OrderBy='name',
9-
9+
1010
# Direction of ordering (Desc/Asc)
1111
[parameter(mandatory=$false)]
1212
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -21,7 +21,7 @@ function Get-ServiceNowUser{
2121
[parameter(ParameterSetName='UseConnectionObject')]
2222
[parameter(ParameterSetName='SetGlobalAuth')]
2323
[int]$Limit=10,
24-
24+
2525
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
2626
[parameter(mandatory=$false)]
2727
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -42,22 +42,22 @@ function Get-ServiceNowUser{
4242
[parameter(ParameterSetName='UseConnectionObject')]
4343
[parameter(ParameterSetName='SetGlobalAuth')]
4444
[ValidateSet("true","false", "all")]
45-
[string]$DisplayValues='false',
45+
[string]$DisplayValues='true',
4646

47-
# Credential used to authenticate to ServiceNow
47+
# Credential used to authenticate to ServiceNow
4848
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
4949
[ValidateNotNullOrEmpty()]
5050
[PSCredential]
51-
$ServiceNowCredential,
51+
$ServiceNowCredential,
5252

53-
# The URL for the ServiceNow instance being used
53+
# The URL for the ServiceNow instance being used
5454
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
5555
[ValidateNotNullOrEmpty()]
5656
[string]
57-
$ServiceNowURL,
57+
$ServiceNowURL,
5858

5959
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
60-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
60+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
6161
[ValidateNotNullOrEmpty()]
6262
[Hashtable]
6363
$Connection
@@ -72,20 +72,20 @@ function Get-ServiceNowUser{
7272
}
7373
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
7474

75-
# Table Splat
75+
# Table Splat
7676
$getServiceNowTableSplat = @{
7777
Table = 'sys_user'
7878
Query = $Query
7979
Limit = $Limit
8080
DisplayValues = $DisplayValues
8181
}
82-
82+
8383
# Update the splat if the parameters have values
8484
if ($null -ne $PSBoundParameters.Connection)
85-
{
85+
{
8686
$getServiceNowTableSplat.Add('Connection',$Connection)
8787
}
88-
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
88+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
8989
{
9090
$getServiceNowTableSplat.Add('ServiceNowCredential',$ServiceNowCredential)
9191
$getServiceNowTableSplat.Add('ServiceNowURL',$ServiceNowURL)

0 commit comments

Comments
 (0)