@@ -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,84 @@ 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+ # Credential used to authenticate to ServiceNow
171+ [Parameter (ParameterSetName = ' SpecifyConnectionFields' , Mandatory = $True )]
172+ [ValidateNotNullOrEmpty ()]
173+ [PSCredential ]
174+ $ServiceNowCredential ,
175+
176+ # The URL for the ServiceNow instance being used (eg: instancename.service-now.com)
177+ [Parameter (ParameterSetName = ' SpecifyConnectionFields' , Mandatory = $True )]
178+ [ValidateNotNullOrEmpty ()]
179+ [string ]
180+ $ServiceNowURL ,
181+
182+ # Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
183+ [Parameter (ParameterSetName = ' UseConnectionObject' , Mandatory = $True )]
184+ [ValidateNotNullOrEmpty ()]
185+ [Hashtable ]
186+ $Connection
100187 )
101188
189+
102190 $Values = @ {
103191 ' caller_id' = $Caller
104192 ' short_description' = $ShortDescription
@@ -109,8 +197,20 @@ function New-ServiceNowIncident{
109197 ' subcategory' = $Subcategory
110198 ' cmdb_ci' = $ConfigurationItem
111199 }
112-
113- New-ServiceNowTableEntry - Table ' incident' - Values $Values
200+
201+
202+ if ($Connection -ne $null )
203+ {
204+ New-ServiceNowTableEntry - Table ' incident' - Values $Values - Connection $Connection
205+ }
206+ elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null )
207+ {
208+ New-ServiceNowTableEntry - Table ' incident' - Values $Values - ServiceNowCredential $ServiceNowCredential - ServiceNowURL $ServiceNowURL
209+ }
210+ else
211+ {
212+ New-ServiceNowTableEntry - Table ' incident' - Values $Values
213+ }
114214
115215}
116216
0 commit comments