Skip to content

Commit 348c3a6

Browse files
authored
Merge pull request #63 from Sam-Martin/development
v1.3.6 - Parameter Standardization
2 parents c54b51c + 746f0ca commit 348c3a6

13 files changed

+239
-326
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-80%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,63 +1,46 @@
11
function Get-ServiceNowChangeRequest {
2-
param(
2+
[OutputType([System.Management.Automation.PSCustomObject])]
3+
[CmdletBinding(DefaultParameterSetName)]
4+
Param(
35
# Machine name of the field to order by
4-
[parameter(mandatory=$false)]
5-
[parameter(ParameterSetName='SpecifyConnectionFields')]
6-
[parameter(ParameterSetName='UseConnectionObject')]
7-
[parameter(ParameterSetName='SetGlobalAuth')]
8-
[string]$OrderBy='opened_at',
6+
[Parameter(Mandatory = $false)]
7+
[string]$OrderBy = 'opened_at',
98

109
# Direction of ordering (Desc/Asc)
11-
[parameter(mandatory=$false)]
12-
[parameter(ParameterSetName='SpecifyConnectionFields')]
13-
[parameter(ParameterSetName='UseConnectionObject')]
14-
[parameter(ParameterSetName='SetGlobalAuth')]
15-
[ValidateSet("Desc", "Asc")]
16-
[string]$OrderDirection='Desc',
10+
[Parameter(Mandatory = $false)]
11+
[ValidateSet('Desc', 'Asc')]
12+
[string]$OrderDirection = 'Desc',
1713

1814
# Maximum number of records to return
19-
[parameter(mandatory=$false)]
20-
[parameter(ParameterSetName='SpecifyConnectionFields')]
21-
[parameter(ParameterSetName='UseConnectionObject')]
22-
[parameter(ParameterSetName='SetGlobalAuth')]
23-
[int]$Limit=10,
15+
[Parameter(Mandatory = $false)]
16+
[int]$Limit = 10,
2417

2518
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
26-
[parameter(mandatory=$false)]
27-
[parameter(ParameterSetName='SpecifyConnectionFields')]
28-
[parameter(ParameterSetName='UseConnectionObject')]
29-
[parameter(ParameterSetName='SetGlobalAuth')]
30-
[hashtable]$MatchExact=@{},
19+
[Parameter(Mandatory = $false)]
20+
[hashtable]$MatchExact = @{},
3121

3222
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
33-
[parameter(mandatory=$false)]
34-
[parameter(ParameterSetName='SpecifyConnectionFields')]
35-
[parameter(ParameterSetName='UseConnectionObject')]
36-
[parameter(ParameterSetName='SetGlobalAuth')]
37-
[hashtable]$MatchContains=@{},
23+
[Parameter(Mandatory = $false)]
24+
[hashtable]$MatchContains = @{},
3825

39-
# Whether to return manipulated display values rather than actual database values.
40-
[parameter(mandatory=$false)]
41-
[parameter(ParameterSetName='SpecifyConnectionFields')]
42-
[parameter(ParameterSetName='UseConnectionObject')]
43-
[parameter(ParameterSetName='SetGlobalAuth')]
44-
[ValidateSet("true","false", "all")]
45-
[string]$DisplayValues='true',
26+
# Whether or not to show human readable display values instead of machine values
27+
[Parameter(Mandatory = $false)]
28+
[ValidateSet('true', 'false', 'all')]
29+
[string]$DisplayValues = 'true',
4630

47-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
31+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
4832
[ValidateNotNullOrEmpty()]
49-
[PSCredential]
50-
$ServiceNowCredential,
33+
[Alias('ServiceNowCredential')]
34+
[PSCredential]$Credential,
5135

52-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
53-
[ValidateNotNullOrEmpty()]
54-
[string]
55-
$ServiceNowURL,
36+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
37+
[ValidateScript({Test-ServiceNowURL -Url $_})]
38+
[Alias('Url')]
39+
[string]$ServiceNowURL,
5640

57-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
41+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $true)]
5842
[ValidateNotNullOrEmpty()]
59-
[Hashtable]
60-
$Connection
43+
[hashtable]$Connection
6144
)
6245

6346
# Query Splat

ServiceNow/Public/Get-ServiceNowConfigurationItem.ps1

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,46 @@
11
function Get-ServiceNowConfigurationItem {
2-
param(
2+
[OutputType([System.Management.Automation.PSCustomObject])]
3+
[CmdletBinding(DefaultParameterSetName)]
4+
Param(
35
# Machine name of the field to order by
4-
[parameter(mandatory=$false)]
5-
[parameter(ParameterSetName='SpecifyConnectionFields')]
6-
[parameter(ParameterSetName='UseConnectionObject')]
7-
[parameter(ParameterSetName='SetGlobalAuth')]
8-
[string]$OrderBy='name',
6+
[Parameter(Mandatory = $false)]
7+
[string]$OrderBy = 'name',
98

109
# Direction of ordering (Desc/Asc)
11-
[parameter(mandatory=$false)]
12-
[parameter(ParameterSetName='SpecifyConnectionFields')]
13-
[parameter(ParameterSetName='UseConnectionObject')]
14-
[parameter(ParameterSetName='SetGlobalAuth')]
15-
[ValidateSet("Desc", "Asc")]
16-
[string]$OrderDirection='Desc',
10+
[Parameter(Mandatory = $false)]
11+
[ValidateSet('Desc', 'Asc')]
12+
[string]$OrderDirection = 'Desc',
1713

1814
# Maximum number of records to return
19-
[parameter(mandatory=$false)]
20-
[parameter(ParameterSetName='SpecifyConnectionFields')]
21-
[parameter(ParameterSetName='UseConnectionObject')]
22-
[parameter(ParameterSetName='SetGlobalAuth')]
23-
[int]$Limit=10,
15+
[Parameter(Mandatory = $false)]
16+
[int]$Limit = 10,
2417

2518
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
26-
[parameter(mandatory=$false)]
27-
[parameter(ParameterSetName='SpecifyConnectionFields')]
28-
[parameter(ParameterSetName='UseConnectionObject')]
29-
[parameter(ParameterSetName='SetGlobalAuth')]
30-
[hashtable]$MatchExact=@{},
19+
[Parameter(Mandatory = $false)]
20+
[hashtable]$MatchExact = @{},
3121

3222
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
33-
[parameter(mandatory=$false)]
34-
[parameter(ParameterSetName='SpecifyConnectionFields')]
35-
[parameter(ParameterSetName='UseConnectionObject')]
36-
[parameter(ParameterSetName='SetGlobalAuth')]
37-
[hashtable]$MatchContains=@{},
23+
[Parameter(Mandatory = $false)]
24+
[hashtable]$MatchContains = @{},
3825

39-
# Whether to return manipulated display values rather than actual database values.
40-
[parameter(mandatory=$false)]
41-
[parameter(ParameterSetName='SpecifyConnectionFields')]
42-
[parameter(ParameterSetName='UseConnectionObject')]
43-
[parameter(ParameterSetName='SetGlobalAuth')]
44-
[ValidateSet("true","false", "all")]
45-
[string]$DisplayValues='true',
26+
# Whether or not to show human readable display values instead of machine values
27+
[Parameter(Mandatory = $false)]
28+
[ValidateSet('true', 'false', 'all')]
29+
[string]$DisplayValues = 'true',
4630

47-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
31+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
4832
[ValidateNotNullOrEmpty()]
49-
[PSCredential]
50-
$ServiceNowCredential,
33+
[Alias('ServiceNowCredential')]
34+
[PSCredential]$Credential,
5135

52-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
53-
[ValidateNotNullOrEmpty()]
54-
[string]
55-
$ServiceNowURL,
36+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
37+
[ValidateScript({Test-ServiceNowURL -Url $_})]
38+
[Alias('Url')]
39+
[string]$ServiceNowURL,
5640

57-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
41+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $true)]
5842
[ValidateNotNullOrEmpty()]
59-
[Hashtable]
60-
$Connection
43+
[hashtable]$Connection
6144
)
6245

6346
# Query Splat

ServiceNow/Public/Get-ServiceNowIncident.ps1

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,46 @@
11
function Get-ServiceNowIncident{
2-
param(
2+
[OutputType([System.Management.Automation.PSCustomObject])]
3+
[CmdletBinding(DefaultParameterSetName)]
4+
Param(
35
# Machine name of the field to order by
4-
[parameter(mandatory=$false)]
5-
[parameter(ParameterSetName='SpecifyConnectionFields')]
6-
[parameter(ParameterSetName='UseConnectionObject')]
7-
[parameter(ParameterSetName='SetGlobalAuth')]
8-
[string]$OrderBy='opened_at',
6+
[Parameter(Mandatory = $false)]
7+
[string]$OrderBy = 'opened_at',
98

109
# Direction of ordering (Desc/Asc)
11-
[parameter(mandatory=$false)]
12-
[parameter(ParameterSetName='SpecifyConnectionFields')]
13-
[parameter(ParameterSetName='UseConnectionObject')]
14-
[parameter(ParameterSetName='SetGlobalAuth')]
15-
[ValidateSet("Desc", "Asc")]
16-
[string]$OrderDirection='Desc',
10+
[Parameter(Mandatory = $false)]
11+
[ValidateSet('Desc', 'Asc')]
12+
[string]$OrderDirection = 'Desc',
1713

1814
# Maximum number of records to return
19-
[parameter(mandatory=$false)]
20-
[parameter(ParameterSetName='SpecifyConnectionFields')]
21-
[parameter(ParameterSetName='UseConnectionObject')]
22-
[parameter(ParameterSetName='SetGlobalAuth')]
23-
[int]$Limit=10,
15+
[Parameter(Mandatory = $false)]
16+
[int]$Limit = 10,
2417

2518
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
26-
[parameter(mandatory=$false)]
27-
[parameter(ParameterSetName='SpecifyConnectionFields')]
28-
[parameter(ParameterSetName='UseConnectionObject')]
29-
[parameter(ParameterSetName='SetGlobalAuth')]
30-
[hashtable]$MatchExact=@{},
19+
[Parameter(Mandatory = $false)]
20+
[hashtable]$MatchExact = @{},
3121

3222
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
33-
[parameter(mandatory=$false)]
34-
[parameter(ParameterSetName='SpecifyConnectionFields')]
35-
[parameter(ParameterSetName='UseConnectionObject')]
36-
[parameter(ParameterSetName='SetGlobalAuth')]
37-
[hashtable]$MatchContains=@{},
23+
[Parameter(Mandatory = $false)]
24+
[hashtable]$MatchContains = @{},
3825

39-
# Whether to return manipulated display values rather than actual database values.
40-
[parameter(mandatory=$false)]
41-
[parameter(ParameterSetName='SpecifyConnectionFields')]
42-
[parameter(ParameterSetName='UseConnectionObject')]
43-
[parameter(ParameterSetName='SetGlobalAuth')]
44-
[ValidateSet("true","false", "all")]
45-
[string]$DisplayValues='true',
26+
# Whether or not to show human readable display values instead of machine values
27+
[Parameter(Mandatory = $false)]
28+
[ValidateSet('true', 'false', 'all')]
29+
[string]$DisplayValues = 'true',
4630

47-
# Credential used to authenticate to ServiceNow
48-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
31+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
4932
[ValidateNotNullOrEmpty()]
50-
[PSCredential]
51-
$ServiceNowCredential,
33+
[Alias('ServiceNowCredential')]
34+
[PSCredential]$Credential,
5235

53-
# The URL for the ServiceNow instance being used
54-
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
55-
[ValidateNotNullOrEmpty()]
56-
[string]
57-
$ServiceNowURL,
36+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $true)]
37+
[ValidateScript({Test-ServiceNowURL -Url $_})]
38+
[Alias('Url')]
39+
[string]$ServiceNowURL,
5840

59-
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
60-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
41+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $true)]
6142
[ValidateNotNullOrEmpty()]
62-
[Hashtable]
63-
$Connection
43+
[hashtable]$Connection
6444
)
6545

6646
# Query Splat

0 commit comments

Comments
 (0)