@@ -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+ }
0 commit comments