41 lines
1.3 KiB
PowerShell
41 lines
1.3 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Creates a new record in a specified ServiceNow table.
|
|
.DESCRIPTION
|
|
This function creates a new record in the specified ServiceNow table using the provided values.
|
|
.PARAMETER Table
|
|
The name of the ServiceNow table where the new record will be created.
|
|
.PARAMETER Values
|
|
A hashtable containing the field names and values for the new record.
|
|
.EXAMPLE
|
|
$values = @{
|
|
short_description = 'New incident';
|
|
description = 'Detailed description of the incident';
|
|
impact = 3;
|
|
urgency = 3;
|
|
}
|
|
New-ITDServiceNowRecord -Table 'incident' -Values $values
|
|
This example creates a new incident record in the ServiceNow 'incident' table with the specified values.
|
|
.NOTES
|
|
Ensure that the ServiceNow session is correctly initialized before calling this function.
|
|
#>
|
|
function New-ITDServiceNowRecord {
|
|
param(
|
|
[string]
|
|
$Table,
|
|
|
|
[hashtable]
|
|
$Values
|
|
)
|
|
|
|
$InvokeRestMethodParams = @{
|
|
Method = 'Post';
|
|
Uri = ($Script:ServiceNowSession.Uri + "/api/now/table/$Table");
|
|
Body = $Values | ConvertTo-Json;
|
|
Headers = $Script:ServiceNowSession.Headers;
|
|
ContentType = "application/json"
|
|
}
|
|
|
|
#Write-Output $InvokeRestMethodParams
|
|
$result = Invoke-RestMethod @InvokeRestMethodParams
|
|
} |