Skip to content

Commit e37cdf2

Browse files
committed
Lost Update-ServiceNowTableEntry in merge. Adding it back.
1 parent 708521e commit e37cdf2

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
function Update-ServiceNowTableEntry{
2+
[CmdletBinding(ConfirmImpact='High')]
3+
Param(
4+
# sys_id of the entry we're deleting
5+
[parameter(mandatory=$true)]
6+
[parameter(ParameterSetName='SpecifyConnectionFields')]
7+
[parameter(ParameterSetName='UseConnectionObject')]
8+
[parameter(ParameterSetName='SetGlobalAuth')]
9+
[string]$SysId,
10+
11+
# Table containing the entry we're deleting
12+
[parameter(mandatory=$true)]
13+
[parameter(ParameterSetName='SpecifyConnectionFields')]
14+
[parameter(ParameterSetName='UseConnectionObject')]
15+
[parameter(ParameterSetName='SetGlobalAuth')]
16+
[string]$Table,
17+
18+
# Credential used to authenticate to ServiceNow
19+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
20+
[ValidateNotNullOrEmpty()]
21+
[PSCredential]$ServiceNowCredential,
22+
23+
# The URL for the ServiceNow instance being used
24+
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
25+
[ValidateNotNullOrEmpty()]
26+
[string]$ServiceNowURL,
27+
28+
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
29+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
30+
[ValidateNotNullOrEmpty()]
31+
[Hashtable]$Connection,
32+
33+
# Hashtable of values to use as the record's properties
34+
[parameter(mandatory=$false)]
35+
[parameter(ParameterSetName='SpecifyConnectionFields')]
36+
[parameter(ParameterSetName='UseConnectionObject')]
37+
[parameter(ParameterSetName='SetGlobalAuth')]
38+
[hashtable]$Values
39+
)
40+
41+
#Get credential and ServiceNow REST URL
42+
if ($Connection -ne $null)
43+
{
44+
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
45+
$ServiceNowCredential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
46+
$ServiceNowURL = 'https://' + $Connection.ServiceNowUri + '/api/now/v1'
47+
48+
}
49+
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null)
50+
{
51+
$ServiceNowURL = 'https://' + $ServiceNowURL + '/api/now/v1'
52+
}
53+
elseif((Test-ServiceNowAuthIsSet))
54+
{
55+
$ServiceNowCredential = $Global:ServiceNowCredentials
56+
$ServiceNowURL = $global:ServiceNowRESTURL
57+
}
58+
else
59+
{
60+
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"
61+
}
62+
63+
$Body = $Values | ConvertTo-Json
64+
65+
#Convert to UTF8 array to support special chars such as the danish "�","�","�"
66+
$utf8Bytes = [System.Text.Encoding]::UTf8.GetBytes($Body)
67+
68+
# Fire and return
69+
$Uri = $ServiceNowURL + "/table/$Table/$SysID"
70+
return (Invoke-RestMethod -Uri $uri -Method Patch -Credential $ServiceNowCredential -Body $utf8Bytes -ContentType "application/json").result
71+
}

0 commit comments

Comments
 (0)