Skip to content

Commit d38b79d

Browse files
Merge upstream changes
2 parents 51f949f + 348c3a6 commit d38b79d

13 files changed

+269
-357
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ServiceNow
22

3-
[![GitHub release](https://img.shields.io/github/release/Sam-Martin/servicenow-powershell.svg)](https://github.com/Sam-Martin/servicenow-powershell/releases/latest) [![GitHub license](https://img.shields.io/github/license/Sam-Martin/servicenow-powershell.svg)](LICENSE) ![Test Coverage](https://img.shields.io/badge/coverage-79%25-yellow.svg)
3+
[![GitHub release](https://img.shields.io/github/release/Sam-Martin/servicenow-powershell.svg)](https://github.com/Sam-Martin/servicenow-powershell/releases/latest) [![GitHub license](https://img.shields.io/github/license/Sam-Martin/servicenow-powershell.svg)](LICENSE) ![Test Coverage](https://img.shields.io/badge/coverage-78%25-yellow.svg)
44

55
This PowerShell module provides a series of cmdlets for interacting with the [ServiceNow REST API](http://wiki.servicenow.com/index.php?title=REST_API), performed by wrapping `Invoke-RestMethod` for the API calls.
66

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Function Test-ServiceNowURL {
2+
<#
3+
.SYNOPSIS
4+
For use in testing ServiceNow Urls.
5+
6+
.DESCRIPTION
7+
For use in testing ServiceNow Urls. The test is a simple regex match in an attempt to validate that users use a 'tenant.domain.com' pattern.
8+
9+
.EXAMPLE
10+
Test-ServiceNowURL -Url tenant.domain.com
11+
12+
This example can have text
13+
14+
.OUTPUTS
15+
System.Boolean
16+
17+
#>
18+
19+
[OutputType([System.Boolean])]
20+
[CmdletBinding()]
21+
param (
22+
# Pipeline variable
23+
[Parameter(Mandatory = $true)]
24+
[ValidateNotNullOrEmpty()]
25+
[string]$Url
26+
)
27+
28+
begin {}
29+
process {
30+
Write-Verbose "Testing url: $Url"
31+
if ($Url -match '^\w+\..*\.\w+') {
32+
$true
33+
}
34+
else {
35+
Throw "The expected URL format is tenant.domain.com"
36+
}
37+
}
38+
end {}
39+
}

ServiceNow/Public/Get-ServiceNowChangeRequest.ps1

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function Get-ServiceNowChangeRequest {
2-
param(
2+
[OutputType([System.Management.Automation.PSCustomObject])]
3+
[CmdletBinding(DefaultParameterSetName)]
4+
Param(
35
# Fields to return
46
[parameter(mandatory = $false)]
57
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
@@ -8,63 +10,44 @@ function Get-ServiceNowChangeRequest {
810
[string[]]$Fields,
911

1012
# Machine name of the field to order by
11-
[parameter(mandatory=$false)]
12-
[parameter(ParameterSetName='SpecifyConnectionFields')]
13-
[parameter(ParameterSetName='UseConnectionObject')]
14-
[parameter(ParameterSetName='SetGlobalAuth')]
15-
[string]$OrderBy='opened_at',
13+
[Parameter(Mandatory = $false)]
14+
[string]$OrderBy = 'opened_at',
1615

1716
# Direction of ordering (Desc/Asc)
18-
[parameter(mandatory=$false)]
19-
[parameter(ParameterSetName='SpecifyConnectionFields')]
20-
[parameter(ParameterSetName='UseConnectionObject')]
21-
[parameter(ParameterSetName='SetGlobalAuth')]
22-
[ValidateSet("Desc", "Asc")]
23-
[string]$OrderDirection='Desc',
17+
[Parameter(Mandatory = $false)]
18+
[ValidateSet('Desc', 'Asc')]
19+
[string]$OrderDirection = 'Desc',
2420

2521
# Maximum number of records to return
26-
[parameter(mandatory=$false)]
27-
[parameter(ParameterSetName='SpecifyConnectionFields')]
28-
[parameter(ParameterSetName='UseConnectionObject')]
29-
[parameter(ParameterSetName='SetGlobalAuth')]
30-
[int]$Limit=10,
22+
[Parameter(Mandatory = $false)]
23+
[int]$Limit = 10,
3124

3225
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
33-
[parameter(mandatory=$false)]
34-
[parameter(ParameterSetName='SpecifyConnectionFields')]
35-
[parameter(ParameterSetName='UseConnectionObject')]
36-
[parameter(ParameterSetName='SetGlobalAuth')]
37-
[hashtable]$MatchExact=@{},
26+
[Parameter(Mandatory = $false)]
27+
[hashtable]$MatchExact = @{},
3828

3929
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
40-
[parameter(mandatory=$false)]
41-
[parameter(ParameterSetName='SpecifyConnectionFields')]
42-
[parameter(ParameterSetName='UseConnectionObject')]
43-
[parameter(ParameterSetName='SetGlobalAuth')]
44-
[hashtable]$MatchContains=@{},
30+
[Parameter(Mandatory = $false)]
31+
[hashtable]$MatchContains = @{},
4532

46-
# Whether to return manipulated display values rather than actual database values.
47-
[parameter(mandatory=$false)]
48-
[parameter(ParameterSetName='SpecifyConnectionFields')]
49-
[parameter(ParameterSetName='UseConnectionObject')]
50-
[parameter(ParameterSetName='SetGlobalAuth')]
51-
[ValidateSet("true","false", "all")]
52-
[string]$DisplayValues='true',
33+
# Whether or not to show human readable display values instead of machine values
34+
[Parameter(Mandatory = $false)]
35+
[ValidateSet('true', 'false', 'all')]
36+
[string]$DisplayValues = 'true',
5337

54-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
38+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
5539
[ValidateNotNullOrEmpty()]
56-
[PSCredential]
57-
$ServiceNowCredential,
40+
[Alias('ServiceNowCredential')]
41+
[PSCredential]$Credential,
5842

59-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
60-
[ValidateNotNullOrEmpty()]
61-
[string]
62-
$ServiceNowURL,
43+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
44+
[ValidateScript({Test-ServiceNowURL -Url $_})]
45+
[Alias('Url')]
46+
[string]$ServiceNowURL,
6347

64-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
48+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $true)]
6549
[ValidateNotNullOrEmpty()]
66-
[Hashtable]
67-
$Connection
50+
[hashtable]$Connection
6851
)
6952

7053
# Query Splat

ServiceNow/Public/Get-ServiceNowConfigurationItem.ps1

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function Get-ServiceNowConfigurationItem {
2-
param(
2+
[OutputType([System.Management.Automation.PSCustomObject])]
3+
[CmdletBinding(DefaultParameterSetName)]
4+
Param(
35
# Fields to return
46
[parameter(mandatory = $false)]
57
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
@@ -8,63 +10,44 @@ function Get-ServiceNowConfigurationItem {
810
[string[]]$Fields,
911

1012
# Machine name of the field to order by
11-
[parameter(mandatory=$false)]
12-
[parameter(ParameterSetName='SpecifyConnectionFields')]
13-
[parameter(ParameterSetName='UseConnectionObject')]
14-
[parameter(ParameterSetName='SetGlobalAuth')]
15-
[string]$OrderBy='name',
13+
[Parameter(Mandatory = $false)]
14+
[string]$OrderBy = 'name',
1615

1716
# Direction of ordering (Desc/Asc)
18-
[parameter(mandatory=$false)]
19-
[parameter(ParameterSetName='SpecifyConnectionFields')]
20-
[parameter(ParameterSetName='UseConnectionObject')]
21-
[parameter(ParameterSetName='SetGlobalAuth')]
22-
[ValidateSet("Desc", "Asc")]
23-
[string]$OrderDirection='Desc',
17+
[Parameter(Mandatory = $false)]
18+
[ValidateSet('Desc', 'Asc')]
19+
[string]$OrderDirection = 'Desc',
2420

2521
# Maximum number of records to return
26-
[parameter(mandatory=$false)]
27-
[parameter(ParameterSetName='SpecifyConnectionFields')]
28-
[parameter(ParameterSetName='UseConnectionObject')]
29-
[parameter(ParameterSetName='SetGlobalAuth')]
30-
[int]$Limit=10,
22+
[Parameter(Mandatory = $false)]
23+
[int]$Limit = 10,
3124

3225
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
33-
[parameter(mandatory=$false)]
34-
[parameter(ParameterSetName='SpecifyConnectionFields')]
35-
[parameter(ParameterSetName='UseConnectionObject')]
36-
[parameter(ParameterSetName='SetGlobalAuth')]
37-
[hashtable]$MatchExact=@{},
26+
[Parameter(Mandatory = $false)]
27+
[hashtable]$MatchExact = @{},
3828

3929
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
40-
[parameter(mandatory=$false)]
41-
[parameter(ParameterSetName='SpecifyConnectionFields')]
42-
[parameter(ParameterSetName='UseConnectionObject')]
43-
[parameter(ParameterSetName='SetGlobalAuth')]
44-
[hashtable]$MatchContains=@{},
30+
[Parameter(Mandatory = $false)]
31+
[hashtable]$MatchContains = @{},
4532

46-
# Whether to return manipulated display values rather than actual database values.
47-
[parameter(mandatory=$false)]
48-
[parameter(ParameterSetName='SpecifyConnectionFields')]
49-
[parameter(ParameterSetName='UseConnectionObject')]
50-
[parameter(ParameterSetName='SetGlobalAuth')]
51-
[ValidateSet("true","false", "all")]
52-
[string]$DisplayValues='true',
33+
# Whether or not to show human readable display values instead of machine values
34+
[Parameter(Mandatory = $false)]
35+
[ValidateSet('true', 'false', 'all')]
36+
[string]$DisplayValues = 'true',
5337

54-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
38+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
5539
[ValidateNotNullOrEmpty()]
56-
[PSCredential]
57-
$ServiceNowCredential,
40+
[Alias('ServiceNowCredential')]
41+
[PSCredential]$Credential,
5842

59-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
60-
[ValidateNotNullOrEmpty()]
61-
[string]
62-
$ServiceNowURL,
43+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
44+
[ValidateScript({Test-ServiceNowURL -Url $_})]
45+
[Alias('Url')]
46+
[string]$ServiceNowURL,
6347

64-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
48+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $true)]
6549
[ValidateNotNullOrEmpty()]
66-
[Hashtable]
67-
$Connection
50+
[hashtable]$Connection
6851
)
6952

7053
# Query Splat

ServiceNow/Public/Get-ServiceNowIncident.ps1

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function Get-ServiceNowIncident{
2-
param(
2+
[OutputType([System.Management.Automation.PSCustomObject])]
3+
[CmdletBinding(DefaultParameterSetName)]
4+
Param(
35
# Fields to return
46
[parameter(mandatory = $false)]
57
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
@@ -8,66 +10,44 @@ function Get-ServiceNowIncident{
810
[string[]]$Fields,
911

1012
# Machine name of the field to order by
11-
[parameter(mandatory=$false)]
12-
[parameter(ParameterSetName='SpecifyConnectionFields')]
13-
[parameter(ParameterSetName='UseConnectionObject')]
14-
[parameter(ParameterSetName='SetGlobalAuth')]
15-
[string]$OrderBy='opened_at',
13+
[Parameter(Mandatory = $false)]
14+
[string]$OrderBy = 'opened_at',
1615

1716
# Direction of ordering (Desc/Asc)
18-
[parameter(mandatory=$false)]
19-
[parameter(ParameterSetName='SpecifyConnectionFields')]
20-
[parameter(ParameterSetName='UseConnectionObject')]
21-
[parameter(ParameterSetName='SetGlobalAuth')]
22-
[ValidateSet("Desc", "Asc")]
23-
[string]$OrderDirection='Desc',
17+
[Parameter(Mandatory = $false)]
18+
[ValidateSet('Desc', 'Asc')]
19+
[string]$OrderDirection = 'Desc',
2420

2521
# Maximum number of records to return
26-
[parameter(mandatory=$false)]
27-
[parameter(ParameterSetName='SpecifyConnectionFields')]
28-
[parameter(ParameterSetName='UseConnectionObject')]
29-
[parameter(ParameterSetName='SetGlobalAuth')]
30-
[int]$Limit=10,
22+
[Parameter(Mandatory = $false)]
23+
[int]$Limit = 10,
3124

3225
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
33-
[parameter(mandatory=$false)]
34-
[parameter(ParameterSetName='SpecifyConnectionFields')]
35-
[parameter(ParameterSetName='UseConnectionObject')]
36-
[parameter(ParameterSetName='SetGlobalAuth')]
37-
[hashtable]$MatchExact=@{},
26+
[Parameter(Mandatory = $false)]
27+
[hashtable]$MatchExact = @{},
3828

3929
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
40-
[parameter(mandatory=$false)]
41-
[parameter(ParameterSetName='SpecifyConnectionFields')]
42-
[parameter(ParameterSetName='UseConnectionObject')]
43-
[parameter(ParameterSetName='SetGlobalAuth')]
44-
[hashtable]$MatchContains=@{},
30+
[Parameter(Mandatory = $false)]
31+
[hashtable]$MatchContains = @{},
4532

46-
# Whether to return manipulated display values rather than actual database values.
47-
[parameter(mandatory=$false)]
48-
[parameter(ParameterSetName='SpecifyConnectionFields')]
49-
[parameter(ParameterSetName='UseConnectionObject')]
50-
[parameter(ParameterSetName='SetGlobalAuth')]
51-
[ValidateSet("true","false", "all")]
52-
[string]$DisplayValues='true',
33+
# Whether or not to show human readable display values instead of machine values
34+
[Parameter(Mandatory = $false)]
35+
[ValidateSet('true', 'false', 'all')]
36+
[string]$DisplayValues = 'true',
5337

54-
# Credential used to authenticate to ServiceNow
55-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
38+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
5639
[ValidateNotNullOrEmpty()]
57-
[PSCredential]
58-
$ServiceNowCredential,
40+
[Alias('ServiceNowCredential')]
41+
[PSCredential]$Credential,
5942

60-
# The URL for the ServiceNow instance being used
61-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
62-
[ValidateNotNullOrEmpty()]
63-
[string]
64-
$ServiceNowURL,
43+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
44+
[ValidateScript({Test-ServiceNowURL -Url $_})]
45+
[Alias('Url')]
46+
[string]$ServiceNowURL,
6547

66-
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
67-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
48+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $true)]
6849
[ValidateNotNullOrEmpty()]
69-
[Hashtable]
70-
$Connection
50+
[hashtable]$Connection
7151
)
7252

7353
# Query Splat

0 commit comments

Comments
 (0)