@@ -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-
66112function 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