Skip to content

Commit 10945dc

Browse files
authored
Merge pull request #6 from Sam-Martin/development
v1.12
2 parents efee4c4 + b619dd1 commit 10945dc

9 files changed

+489
-47
lines changed

MAKE.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ $PackageFilePatternExclusions = @(
6666

6767
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
6868

69-
$Version = "0.1.2"
69+
$Version = "0.1.12"
7070
$ModuleName = "PSServiceNow"
7171
$PackageName = "$ModuleName-v$($version).zip";
7272

PSServiceNow-Automation.json

1.56 KB
Binary file not shown.

PSServiceNow-Changes.psm1

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,79 @@ function Get-ServiceNowChangeRequest {
22
param(
33
# Machine name of the field to order by
44
[parameter(mandatory=$false)]
5+
[parameter(ParameterSetName='SpecifyConnectionFields')]
6+
[parameter(ParameterSetName='UseConnectionObject')]
7+
[parameter(ParameterSetName='SetGlobalAuth')]
58
[string]$OrderBy='opened_at',
69

710
# Direction of ordering (Desc/Asc)
811
[parameter(mandatory=$false)]
12+
[parameter(ParameterSetName='SpecifyConnectionFields')]
13+
[parameter(ParameterSetName='UseConnectionObject')]
14+
[parameter(ParameterSetName='SetGlobalAuth')]
915
[ValidateSet("Desc", "Asc")]
1016
[string]$OrderDirection='Desc',
1117

1218
# Maximum number of records to return
1319
[parameter(mandatory=$false)]
20+
[parameter(ParameterSetName='SpecifyConnectionFields')]
21+
[parameter(ParameterSetName='UseConnectionObject')]
22+
[parameter(ParameterSetName='SetGlobalAuth')]
1423
[int]$Limit=10,
1524

1625
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
1726
[parameter(mandatory=$false)]
27+
[parameter(ParameterSetName='SpecifyConnectionFields')]
28+
[parameter(ParameterSetName='UseConnectionObject')]
29+
[parameter(ParameterSetName='SetGlobalAuth')]
1830
[hashtable]$MatchExact=@{},
1931

2032
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
2133
[parameter(mandatory=$false)]
34+
[parameter(ParameterSetName='SpecifyConnectionFields')]
35+
[parameter(ParameterSetName='UseConnectionObject')]
36+
[parameter(ParameterSetName='SetGlobalAuth')]
2237
[hashtable]$MatchContains=@{},
2338

2439
# Whether or not to show human readable display values instead of machine values
2540
[parameter(mandatory=$false)]
41+
[parameter(ParameterSetName='SpecifyConnectionFields')]
42+
[parameter(ParameterSetName='UseConnectionObject')]
43+
[parameter(ParameterSetName='SetGlobalAuth')]
2644
[ValidateSet("true","false", "all")]
27-
[string]$DisplayValues='true'
28-
)
45+
[string]$DisplayValues='true',
46+
47+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
48+
[ValidateNotNullOrEmpty()]
49+
[PSCredential]
50+
$ServiceNowCredential,
2951

52+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
53+
[ValidateNotNullOrEmpty()]
54+
[string]
55+
$ServiceNowURL,
56+
57+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
58+
[ValidateNotNullOrEmpty()]
59+
[Hashtable]
60+
$Connection
61+
)
62+
3063
$private:Query = New-ServiceNowQuery -OrderBy $private:OrderBy -OrderDirection $private:OrderDirection -MatchExact $private:MatchExact -MatchContains $private:MatchContains
31-
32-
$private:result = Get-ServiceNowTable -Table 'change_request' -Query $private:Query -Limit $private:Limit -DisplayValues $private:DisplayValues;
64+
65+
66+
if ($Connection -ne $null) {
67+
$private:result = Get-ServiceNowTable -Table 'change_request' -Query $private:Query -Limit $private:Limit -DisplayValues $private:DisplayValues -Connection $Connection
68+
}
69+
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null) {
70+
$private:result = Get-ServiceNowTable -Table 'change_request' -Query $private:Query -Limit $private:Limit -DisplayValues $private:DisplayValues -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
71+
}
72+
else {
73+
$private:result = Get-ServiceNowTable -Table 'change_request' -Query $private:Query -Limit $private:Limit -DisplayValues $private:DisplayValues
74+
}
3375

3476
# Add the custom type to the change request to enable a view
3577
$private:result | %{$_.psobject.TypeNames.Insert(0, "PSServiceNow.ChangeRequest")}
3678
return $private:result
37-
}
79+
}
80+

PSServiceNow-ConfigurationManagement.psm1

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,76 @@ function Get-ServiceNowConfigurationItem {
22
param(
33
# Machine name of the field to order by
44
[parameter(mandatory=$false)]
5+
[parameter(ParameterSetName='SpecifyConnectionFields')]
6+
[parameter(ParameterSetName='UseConnectionObject')]
7+
[parameter(ParameterSetName='SetGlobalAuth')]
58
[string]$OrderBy='name',
69

710
# Direction of ordering (Desc/Asc)
811
[parameter(mandatory=$false)]
12+
[parameter(ParameterSetName='SpecifyConnectionFields')]
13+
[parameter(ParameterSetName='UseConnectionObject')]
14+
[parameter(ParameterSetName='SetGlobalAuth')]
915
[ValidateSet("Desc", "Asc")]
1016
[string]$OrderDirection='Desc',
1117

1218
# Maximum number of records to return
1319
[parameter(mandatory=$false)]
20+
[parameter(ParameterSetName='SpecifyConnectionFields')]
21+
[parameter(ParameterSetName='UseConnectionObject')]
22+
[parameter(ParameterSetName='SetGlobalAuth')]
1423
[int]$Limit=10,
1524

1625
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
1726
[parameter(mandatory=$false)]
27+
[parameter(ParameterSetName='SpecifyConnectionFields')]
28+
[parameter(ParameterSetName='UseConnectionObject')]
29+
[parameter(ParameterSetName='SetGlobalAuth')]
1830
[hashtable]$MatchExact=@{},
1931

2032
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
2133
[parameter(mandatory=$false)]
34+
[parameter(ParameterSetName='SpecifyConnectionFields')]
35+
[parameter(ParameterSetName='UseConnectionObject')]
36+
[parameter(ParameterSetName='SetGlobalAuth')]
2237
[hashtable]$MatchContains=@{},
2338

2439
# Whether or not to show human readable display values instead of machine values
2540
[parameter(mandatory=$false)]
41+
[parameter(ParameterSetName='SpecifyConnectionFields')]
42+
[parameter(ParameterSetName='UseConnectionObject')]
43+
[parameter(ParameterSetName='SetGlobalAuth')]
2644
[ValidateSet("true","false", "all")]
27-
[string]$DisplayValues='true'
45+
[string]$DisplayValues='true',
46+
47+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
48+
[ValidateNotNullOrEmpty()]
49+
[PSCredential]
50+
$ServiceNowCredential,
51+
52+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
53+
[ValidateNotNullOrEmpty()]
54+
[string]
55+
$ServiceNowURL,
56+
57+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
58+
[ValidateNotNullOrEmpty()]
59+
[Hashtable]
60+
$Connection
2861
)
2962

3063
$Query = New-ServiceNowQuery -OrderBy $OrderBy -OrderDirection $OrderDirection -MatchExact $MatchExact -MatchContains $MatchContains
31-
32-
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues;
64+
65+
if ($Connection -ne $null) {
66+
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -Connection $Connection
67+
}
68+
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null) {
69+
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
70+
}
71+
else {
72+
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues
73+
}
74+
3375

3476
# Set the default property set for the table view
3577
$DefaultProperties = @('name', 'category', 'subcategory')

PSServiceNow-Incidents.psm1

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,82 @@ function Get-ServiceNowIncident{
1515
param(
1616
# Machine name of the field to order by
1717
[parameter(mandatory=$false)]
18+
[parameter(ParameterSetName='SpecifyConnectionFields')]
19+
[parameter(ParameterSetName='UseConnectionObject')]
20+
[parameter(ParameterSetName='SetGlobalAuth')]
1821
[string]$OrderBy='opened_at',
1922

2023
# Direction of ordering (Desc/Asc)
2124
[parameter(mandatory=$false)]
25+
[parameter(ParameterSetName='SpecifyConnectionFields')]
26+
[parameter(ParameterSetName='UseConnectionObject')]
27+
[parameter(ParameterSetName='SetGlobalAuth')]
2228
[ValidateSet("Desc", "Asc")]
2329
[string]$OrderDirection='Desc',
2430

2531
# Maximum number of records to return
2632
[parameter(mandatory=$false)]
33+
[parameter(ParameterSetName='SpecifyConnectionFields')]
34+
[parameter(ParameterSetName='UseConnectionObject')]
35+
[parameter(ParameterSetName='SetGlobalAuth')]
2736
[int]$Limit=10,
2837

2938
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
3039
[parameter(mandatory=$false)]
40+
[parameter(ParameterSetName='SpecifyConnectionFields')]
41+
[parameter(ParameterSetName='UseConnectionObject')]
42+
[parameter(ParameterSetName='SetGlobalAuth')]
3143
[hashtable]$MatchExact=@{},
3244

3345
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
3446
[parameter(mandatory=$false)]
47+
[parameter(ParameterSetName='SpecifyConnectionFields')]
48+
[parameter(ParameterSetName='UseConnectionObject')]
49+
[parameter(ParameterSetName='SetGlobalAuth')]
3550
[hashtable]$MatchContains=@{},
3651

3752
# Whether or not to show human readable display values instead of machine values
3853
[parameter(mandatory=$false)]
54+
[parameter(ParameterSetName='SpecifyConnectionFields')]
55+
[parameter(ParameterSetName='UseConnectionObject')]
56+
[parameter(ParameterSetName='SetGlobalAuth')]
3957
[ValidateSet("true","false", "all")]
40-
[string]$DisplayValues='true'
58+
[string]$DisplayValues='true',
59+
60+
# Credential used to authenticate to ServiceNow
61+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
62+
[ValidateNotNullOrEmpty()]
63+
[PSCredential]
64+
$ServiceNowCredential,
65+
66+
# The URL for the ServiceNow instance being used
67+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
68+
[ValidateNotNullOrEmpty()]
69+
[string]
70+
$ServiceNowURL,
71+
72+
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
73+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
74+
[ValidateNotNullOrEmpty()]
75+
[Hashtable]
76+
$Connection
4177
)
4278

4379
$Query = New-ServiceNowQuery -OrderBy $OrderBy -OrderDirection $OrderDirection -MatchExact $MatchExact -MatchContains $MatchContains
44-
45-
$result = Get-ServiceNowTable -Table 'incident' -Query $Query -Limit $Limit -DisplayValues $DisplayValues;
4680

81+
if ($Connection -ne $null)
82+
{
83+
$result = Get-ServiceNowTable -Table 'incident' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -Connection $Connection
84+
}
85+
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null)
86+
{
87+
$result = Get-ServiceNowTable -Table 'incident' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
88+
}
89+
else
90+
{
91+
$result = Get-ServiceNowTable -Table 'incident' -Query $Query -Limit $Limit -DisplayValues $DisplayValues
92+
}
93+
4794
# Set the default property set for the table view
4895
$DefaultProperties = @('number', 'short_description', 'opened_at')
4996
$DefaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet(DefaultDisplayPropertySet,[string[]]$DefaultProperties)
@@ -62,43 +109,91 @@ function Get-ServiceNowIncident{
62109
-Comment "Comment" -ConfigurationItem "bee8e0ed6f8475001855fa0dba3ee4ea" `
63110
-Caller "7a4b573a6f3725001855fa0dba3ee485" `
64111
#>
65-
66112
function New-ServiceNowIncident{
67113
Param(
68114

69115
# sys_id of the caller of the incident (user Get-ServiceNowUser to retrieve this)
70-
[parameter(mandatory=$true)]
116+
[parameter(ParameterSetName='SpecifyConnectionFields', mandatory=$true)]
117+
[parameter(ParameterSetName='UseConnectionObject', mandatory=$true)]
118+
[parameter(ParameterSetName='SetGlobalAuth', mandatory=$true)]
71119
[string]$Caller,
72120

73121
# Short description of the incident
74122
[parameter(mandatory=$true)]
123+
[parameter(ParameterSetName='SpecifyConnectionFields', mandatory=$true)]
124+
[parameter(ParameterSetName='UseConnectionObject', mandatory=$true)]
125+
[parameter(ParameterSetName='SetGlobalAuth', mandatory=$true)]
75126
[string]$ShortDescription,
76127

77128
# Long description of the incident
78129
[parameter(mandatory=$false)]
130+
[parameter(ParameterSetName='SpecifyConnectionFields')]
131+
[parameter(ParameterSetName='UseConnectionObject')]
132+
[parameter(ParameterSetName='SetGlobalAuth')]
79133
[string]$Description,
80134

81135
# sys_id of the assignment group (use Get-ServiceNowUserGroup to retrieve this)
82136
[parameter(mandatory=$false)]
137+
[parameter(ParameterSetName='SpecifyConnectionFields')]
138+
[parameter(ParameterSetName='UseConnectionObject')]
139+
[parameter(ParameterSetName='SetGlobalAuth')]
83140
[string]$AssignmentGroup,
84141

85142
# Comment to include in the ticket
86-
[parameter(mandatory=$false)]
143+
[parameter(mandatory=$false)]
144+
[parameter(ParameterSetName='SpecifyConnectionFields')]
145+
[parameter(ParameterSetName='UseConnectionObject')]
146+
[parameter(ParameterSetName='SetGlobalAuth')]
87147
[string]$Comment,
88148

89149
# Category of the incident (e.g. 'Network')
90-
[parameter(mandatory=$false)]
150+
[parameter(mandatory=$false)]
151+
[parameter(ParameterSetName='SpecifyConnectionFields')]
152+
[parameter(ParameterSetName='UseConnectionObject')]
153+
[parameter(ParameterSetName='SetGlobalAuth')]
91154
[string]$Category,
92155

93156
# Subcategory of the incident (e.g. 'Network')
94157
[parameter(mandatory=$false)]
158+
[parameter(ParameterSetName='SpecifyConnectionFields')]
159+
[parameter(ParameterSetName='UseConnectionObject')]
160+
[parameter(ParameterSetName='SetGlobalAuth')]
95161
[string]$Subcategory,
96162

97163
# sys_id of the configuration item of the incident
98164
[parameter(mandatory=$false)]
99-
[string]$ConfigurationItem
165+
[parameter(ParameterSetName='SpecifyConnectionFields')]
166+
[parameter(ParameterSetName='UseConnectionObject')]
167+
[parameter(ParameterSetName='SetGlobalAuth')]
168+
[string]$ConfigurationItem,
169+
170+
# custom fields as hashtable
171+
[parameter(mandatory=$false)]
172+
[parameter(ParameterSetName='SpecifyConnectionFields')]
173+
[parameter(ParameterSetName='UseConnectionObject')]
174+
[parameter(ParameterSetName='SetGlobalAuth')]
175+
[hashtable]$CustomFields,
176+
177+
# Credential used to authenticate to ServiceNow
178+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
179+
[ValidateNotNullOrEmpty()]
180+
[PSCredential]
181+
$ServiceNowCredential,
182+
183+
# The URL for the ServiceNow instance being used (eg: instancename.service-now.com)
184+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
185+
[ValidateNotNullOrEmpty()]
186+
[string]
187+
$ServiceNowURL,
188+
189+
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
190+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
191+
[ValidateNotNullOrEmpty()]
192+
[Hashtable]
193+
$Connection
100194
)
101195

196+
102197
$Values = @{
103198
'caller_id' = $Caller
104199
'short_description' = $ShortDescription
@@ -109,8 +204,24 @@ function New-ServiceNowIncident{
109204
'subcategory' = $Subcategory
110205
'cmdb_ci' = $ConfigurationItem
111206
}
112-
113-
New-ServiceNowTableEntry -Table 'incident' -Values $Values
207+
208+
if($CustomFields)
209+
{
210+
$Values += $CustomFields
211+
}
212+
213+
if ($Connection -ne $null)
214+
{
215+
New-ServiceNowTableEntry -Table 'incident' -Values $Values -Connection $Connection
216+
}
217+
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null)
218+
{
219+
New-ServiceNowTableEntry -Table 'incident' -Values $Values -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
220+
}
221+
else
222+
{
223+
New-ServiceNowTableEntry -Table 'incident' -Values $Values
224+
}
114225

115226
}
116227

0 commit comments

Comments
 (0)