Skip to content

Commit ee67865

Browse files
authored
Merge pull request #93 from Sam-Martin/development
v1.8.0 - Add Update-ServiceNowRequestItem
2 parents 4d9f359 + b3554db commit ee67865

12 files changed

+201
-60
lines changed

ServiceNow/Public/Add-ServiceNowAttachment.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ Function Add-ServiceNowAttachment {
100100
'SpecifyConnectionFields' {
101101
$getServiceNowTableEntry.Add('Credential', $Credential)
102102
$getServiceNowTableEntry.Add('ServiceNowURL', $ServiceNowURL)
103+
break
103104
}
104105
'UseConnectionObject' {
105106
$getServiceNowTableEntry.Add('Connection', $Connection)
107+
break
106108
}
107109
Default {
108110
If (-not (Test-ServiceNowAuthIsSet)) {
@@ -117,11 +119,13 @@ Function Add-ServiceNowAttachment {
117119
Switch ($PSCmdlet.ParameterSetName) {
118120
'SpecifyConnectionFields' {
119121
$ApiUrl = 'https://' + $ServiceNowURL + '/api/now/v1/attachment'
122+
break
120123
}
121124
'UseConnectionObject' {
122125
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
123126
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
124127
$ApiUrl = 'https://' + $Connection.ServiceNowUri + '/api/now/v1/attachment'
128+
break
125129
}
126130
Default {
127131
If ((Test-ServiceNowAuthIsSet)) {

ServiceNow/Public/Get-ServiceNowAttachment.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ Function Get-ServiceNowAttachment {
106106
Switch ($PSCmdlet.ParameterSetName) {
107107
'SpecifyConnectionFields' {
108108
$ApiUrl = 'https://' + $ServiceNowURL + '/api/now/v1/attachment'
109+
break
109110
}
110111
'UseConnectionObject' {
111112
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
112113
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
113114
$ApiUrl = 'https://' + $Connection.ServiceNowUri + '/api/now/v1/attachment'
115+
break
114116
}
115117
Default {
116118
If ((Test-ServiceNowAuthIsSet)) {

ServiceNow/Public/Get-ServiceNowAttachmentDetail.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ Function Get-ServiceNowAttachmentDetail {
8484
'SpecifyConnectionFields' {
8585
$getServiceNowTableEntry.Add('Credential', $Credential)
8686
$getServiceNowTableEntry.Add('ServiceNowURL', $ServiceNowURL)
87+
break
8788
}
8889
'UseConnectionObject' {
8990
$getServiceNowTableEntry.Add('Connection', $Connection)
91+
break
9092
}
9193
Default {
9294
If (-not (Test-ServiceNowAuthIsSet)) {
@@ -101,11 +103,13 @@ Function Get-ServiceNowAttachmentDetail {
101103
Switch ($PSCmdlet.ParameterSetName) {
102104
'SpecifyConnectionFields' {
103105
$ApiUrl = 'https://' + $ServiceNowURL + '/api/now/v1/attachment'
106+
break
104107
}
105108
'UseConnectionObject' {
106109
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
107110
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
108111
$ApiUrl = 'https://' + $Connection.ServiceNowUri + '/api/now/v1/attachment'
112+
break
109113
}
110114
Default {
111115
If ((Test-ServiceNowAuthIsSet)) {

ServiceNow/Public/Get-ServiceNowTableEntry.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ function Get-ServiceNowTableEntry {
9696
'SpecifyConnectionFields' {
9797
$getServiceNowTableSplat.Add('Credential', $Credential)
9898
$getServiceNowTableSplat.Add('ServiceNowURL', $ServiceNowURL)
99+
break
99100
}
100101
'UseConnectionObject' {
101102
$getServiceNowTableSplat.Add('Connection', $Connection)
103+
break
102104
}
103105
Default {}
104106
}

ServiceNow/Public/New-ServiceNowChangeRequest.ps1

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,60 @@ function New-ServiceNowChangeRequest {
22
<#
33
.SYNOPSIS
44
Generates a new ServiceNow change request
5-
5+
66
.DESCRIPTION
77
Generates a new ServiceNow change request using predefined or custom fields by invoking the ServiceNow API
8-
8+
99
.PARAMETER Caller
1010
sys_id of the caller of the change request (user Get-ServiceNowUser to retrieve this)
11-
11+
1212
.PARAMETER ShortDescription
1313
Short description of the change request
14-
14+
1515
.PARAMETER Description
1616
Long description of the change request
17-
17+
1818
.PARAMETER AssignmentGroup
1919
sys_id of the assignment group (use Get-ServiceNowUserGroup to retrieve this)
20-
20+
2121
.PARAMETER Comment
2222
Comment to include in the ticket
23-
23+
2424
.PARAMETER Category
2525
Category of the change request (e.g. 'Network')
26-
26+
2727
.PARAMETER Subcategory
2828
Subcategory of the change request (e.g. 'Network')
29-
29+
3030
.PARAMETER ConfigurationItem
3131
sys_id of the configuration item of the change request
32-
32+
3333
.PARAMETER CustomFields
3434
Custom fields as hashtable
35-
35+
3636
.PARAMETER ServiceNowCredential
3737
Credential used to authenticate to ServiceNow
38-
38+
3939
.PARAMETER ServiceNowURL
4040
The URL for the ServiceNow instance being used (eg: instancename.service-now.com)
41-
41+
4242
.PARAMETER Connection
4343
Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
44-
44+
4545
.PARAMETER PassThru
4646
Returns the ticket values after creation
47-
47+
4848
.LINK
4949
https://github.com/Sam-Martin/servicenow-powershell
50-
50+
5151
.EXAMPLE
5252
Generate a basic change request attributed to the caller "UserName" with descriptions, categories, assignment groups and CMDB items set.
53-
53+
5454
New-ServiceNowchange request -Caller UserName -ShortDescription 'New PS change request' -Description 'This change request was created from Powershell' -AssignmentGroup ServiceDesk -Comment 'Inline Comment' -Category Office -Subcategory Outlook -ConfigurationItem UserPC1
55-
55+
5656
.EXAMPLE
5757
Generate an Change Request by 'splatting' all fields used in the 1st example plus some additional custom ServiceNow fields (These must exist in your ServiceNow instance), This example uses the caller's sys_id value for identification.
58-
58+
5959
$newServiceNowChangeRequestSplat = @{
6060
Caller = '55ccf91161924edc979d8e7e5627a47d'
6161
ShortDescription = 'New PS Change Request'
@@ -72,53 +72,53 @@ function New-ServiceNowChangeRequest {
7272
}
7373
New-ServiceNowChangeRequest @newServiceNowChangeRequestSplat
7474
#>
75-
75+
7676
[CmdletBinding(DefaultParameterSetName, SupportsShouldProcess)]
7777
Param(
7878
[parameter(Mandatory = $true)]
7979
[string]$Caller,
80-
80+
8181
[parameter(Mandatory = $true)]
8282
[string]$ShortDescription,
83-
83+
8484
[parameter(Mandatory = $false)]
8585
[string]$Description,
86-
86+
8787
[parameter(Mandatory = $false)]
8888
[string]$AssignmentGroup,
89-
89+
9090
[parameter(Mandatory = $false)]
9191
[string]$Comment,
92-
92+
9393
[parameter(Mandatory = $false)]
9494
[string]$Category,
95-
95+
9696
[parameter(Mandatory = $false)]
9797
[string]$Subcategory,
98-
98+
9999
[parameter(Mandatory = $false)]
100100
[string]$ConfigurationItem,
101-
101+
102102
[parameter(Mandatory = $false)]
103103
[hashtable]$CustomFields,
104-
104+
105105
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)]
106106
[ValidateNotNullOrEmpty()]
107107
[PSCredential]$ServiceNowCredential,
108-
108+
109109
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)]
110110
[ValidateNotNullOrEmpty()]
111111
[string]$ServiceNowURL,
112-
112+
113113
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $True)]
114114
[ValidateNotNullOrEmpty()]
115115
[Hashtable]$Connection,
116-
116+
117117
# Switch to allow the results to be passed back
118118
[Parameter(Mandatory = $false)]
119119
[switch]$PassThru
120120
)
121-
121+
122122
begin { }
123123
process {
124124
Try {
@@ -129,19 +129,19 @@ function New-ServiceNowChangeRequest {
129129
If ($null -ne $PSBoundParameters.$Parameter) {
130130
# Turn the defined parameter name into the ServiceNow attribute name
131131
$KeyToAdd = Switch ($Parameter) {
132-
AssignmentGroup { 'assignment_group' }
133-
Caller { 'caller_id' }
134-
Category { 'category' }
135-
Comment { 'comments' }
136-
ConfigurationItem { 'cmdb_ci' }
137-
Description { 'description' }
138-
ShortDescription { 'short_description' }
139-
Subcategory { 'subcategory' }
132+
AssignmentGroup {'assignment_group'; break}
133+
Caller {'caller_id'; break}
134+
Category {'category'; break}
135+
Comment {'comments'; break}
136+
ConfigurationItem {'cmdb_ci'; break}
137+
Description {'description'; break}
138+
ShortDescription {'short_description'; break}
139+
Subcategory {'subcategory'; break}
140140
}
141141
$TableEntryValues.Add($KeyToAdd, $PSBoundParameters.$Parameter)
142142
}
143143
}
144-
144+
145145
# Add CustomFields hash pairs to the Table Entry Values hash table
146146
If ($null -ne $PSBoundParameters.CustomFields) {
147147
$DuplicateTableEntryValues = ForEach ($Key in $CustomFields.Keys) {
@@ -155,19 +155,19 @@ function New-ServiceNowChangeRequest {
155155
}
156156
}
157157
}
158-
158+
159159
# Throw an error if duplicate fields were provided
160160
If ($null -ne $DuplicateTableEntryValues) {
161161
$DuplicateKeyList = $DuplicateTableEntryValues -join ","
162162
Throw "Ticket fields may only be used once: $DuplicateKeyList"
163163
}
164-
164+
165165
# Table Entry Splat
166166
$newServiceNowTableEntrySplat = @{
167167
Table = 'change_request'
168168
Values = $TableEntryValues
169169
}
170-
170+
171171
# Update the splat if the parameters have values
172172
If ($null -ne $PSBoundParameters.Connection) {
173173
$newServiceNowTableEntrySplat.Add('Connection', $Connection)
@@ -176,11 +176,11 @@ function New-ServiceNowChangeRequest {
176176
$newServiceNowTableEntrySplat.Add('ServiceNowCredential', $ServiceNowCredential)
177177
$newServiceNowTableEntrySplat.Add('ServiceNowURL', $ServiceNowURL)
178178
}
179-
179+
180180
# Create the table entry
181181
If ($PSCmdlet.ShouldProcess($Uri, $MyInvocation.MyCommand)) {
182182
$Result = New-ServiceNowTableEntry @newServiceNowTableEntrySplat
183-
183+
184184
# Option to return results
185185
If ($PSBoundParameters.ContainsKey('Passthru')) {
186186
$Result
@@ -192,4 +192,4 @@ function New-ServiceNowChangeRequest {
192192
}
193193
}
194194
end { }
195-
}
195+
}

ServiceNow/Public/New-ServiceNowIncident.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ function New-ServiceNowIncident{
119119
If ($null -ne $PSBoundParameters.$Parameter) {
120120
# Turn the defined parameter name into the ServiceNow attribute name
121121
$KeyToAdd = Switch ($Parameter) {
122-
AssignmentGroup {'assignment_group'}
123-
Caller {'caller_id'}
124-
Category {'category'}
125-
Comment {'comments'}
126-
ConfigurationItem {'cmdb_ci'}
127-
Description {'description'}
128-
ShortDescription {'short_description'}
129-
Subcategory {'subcategory'}
122+
AssignmentGroup {'assignment_group'; break}
123+
Caller {'caller_id'; break}
124+
Category {'category'; break}
125+
Comment {'comments'; break}
126+
ConfigurationItem {'cmdb_ci'; break}
127+
Description {'description'; break}
128+
ShortDescription {'short_description'; break}
129+
Subcategory {'subcategory'; break}
130130
}
131131
$TableEntryValues.Add($KeyToAdd,$PSBoundParameters.$Parameter)
132132
}

ServiceNow/Public/New-ServiceNowQuery.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function New-ServiceNowQuery {
4949

5050
# Start the query off with a order direction
5151
$Order = Switch ($OrderDirection) {
52-
'Asc' {'ORDERBY'}
52+
'Asc' {'ORDERBY'; break}
5353
Default {'ORDERBYDESC'}
5454
}
5555
[void]$Query.Append($Order)

ServiceNow/Public/Remove-ServiceNowAttachment.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ Function Remove-ServiceNowAttachment {
6060
Switch ($PSCmdlet.ParameterSetName) {
6161
'SpecifyConnectionFields' {
6262
$ApiUrl = 'https://' + $ServiceNowURL + '/api/now/v1/attachment'
63+
break
6364
}
6465
'UseConnectionObject' {
6566
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
6667
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
6768
$ApiUrl = 'https://' + $Connection.ServiceNowUri + '/api/now/v1/attachment'
69+
break
6870
}
6971
Default {
7072
If (Test-ServiceNowAuthIsSet) {

ServiceNow/Public/Update-ServiceNowNumber.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ Function Update-ServiceNowNumber {
7373
$getServiceNowTableEntry.Add('ServiceNowCredential',$Credential)
7474
$getServiceNowTableEntry.Add('ServiceNowURL',$ServiceNowURL)
7575
$ServiceNowURL = 'https://' + $ServiceNowURL + '/api/now/v1'
76+
break
7677
}
7778
'UseConnectionObject' {
7879
$getServiceNowTableEntry.Add('Connection',$Connection)
7980
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
8081
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
8182
$ServiceNowURL = 'https://' + $Connection.ServiceNowUri + '/api/now/v1'
83+
break
8284
}
8385
Default {
8486
If ((Test-ServiceNowAuthIsSet)) {

0 commit comments

Comments
 (0)