@@ -156,7 +156,7 @@ function New-ServiceNowTableEntry{
156156 Untested
157157#>
158158function Remove-ServiceNowTableEntry {
159- [CmdletBinding (ConfirmImpact = ' High' )]
159+ [CmdletBinding (ConfirmImpact = ' High' )]
160160 Param (
161161 # sys_id of the entry we're deleting
162162 [parameter (mandatory = $true )]
@@ -191,58 +191,7 @@ function Remove-ServiceNowTableEntry{
191191 $Connection
192192 )
193193
194- # Get credential and ServiceNow REST URL
195- if ($Connection -ne $null )
196- {
197- $ConnectionInfo = Get-ConnectionInfo - Connection $Connection
198- }
199- elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null )
200- {
201- $ConnectionInfo = Get-ConnectionInfo - ServiceNowCredential $ServiceNowCredential - ServiceNowURL $ServiceNowURL
202- }
203- else
204- {
205- $ConnectionInfo = Get-ConnectionInfo - UseGlobalAuth $true
206- }
207-
208-
209- # Fire and return
210- $Uri = $ConnectionInfo [" URL" ] + " /table/$Table /$SysID "
211- return (Invoke-RestMethod - Uri $uri - Method Delete - Credential $ConnectionInfo [" Credential" ] - Body $Body - ContentType " application/json" - UseBasicParsing).result
212- }
213-
214-
215- function Get-ConnectionInfo
216- {
217- [OutputType ([HashTable ])]
218- param (
219- # Credential used to authenticate to ServiceNow
220- [Parameter (ParameterSetName = ' SpecifyConnectionFields' , Mandatory = $True )]
221- [ValidateNotNullOrEmpty ()]
222- [PSCredential ]
223- $ServiceNowCredential ,
224-
225- # The URL for the ServiceNow instance being used
226- [Parameter (ParameterSetName = ' SpecifyConnectionFields' , Mandatory = $True )]
227- [ValidateNotNullOrEmpty ()]
228- [string ]
229- $ServiceNowURL ,
230-
231- # Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
232- [Parameter (ParameterSetName = ' UseConnectionObject' , Mandatory = $True )]
233- [ValidateNotNullOrEmpty ()]
234- [Hashtable ]
235- $Connection ,
236-
237- [Parameter (ParameterSetName = ' SetGlobalAuth' , Mandatory = $True )]
238- [ValidateNotNullOrEmpty ()]
239- [Bool ]
240- $UseGlobalAuth
241-
242- )
243-
244-
245- # Get credential and ServiceNow REST URL
194+ # Get credential and ServiceNow REST URL
246195 if ($Connection -ne $null )
247196 {
248197 $SecurePassword = ConvertTo-SecureString $Connection.Password - AsPlainText - Force
@@ -264,9 +213,7 @@ function Get-ConnectionInfo
264213 throw " Exception: You must do one of the following to authenticate: `n 1. Call the Set-ServiceNowAuth cmdlet `n 2. Pass in an Azure Automation connection object `n 3. Pass in an endpoint and credential"
265214 }
266215
267- $Connectioninfo = @ {}
268- $ConnectionInfo.Add (" Credential" , $ServiceNowCredential )
269- $Connectioninfo.Add (" URL" , $ServiceNowURL )
270-
271- return $Connectioninfo
216+ # Fire and return
217+ $Uri = $ServiceNowURL + " /table/$Table /$SysID "
218+ return (Invoke-RestMethod - Uri $uri - Method Delete - Credential $ServiceNowCredential - Body $Body - ContentType " application/json" ).result
272219}
0 commit comments