|
1 | 1 | function Update-ServiceNowRequestItem { |
2 | | - Param |
3 | | - ( # sys_id of the caller of the Request Item (use Get-ServiceNowUser to retrieve this) |
4 | | - [parameter(mandatory=$true)] |
5 | | - [parameter(ParameterSetName='SpecifyConnectionFields', mandatory=$true)] |
6 | | - [parameter(ParameterSetName='UseConnectionObject', mandatory=$true)] |
7 | | - [parameter(ParameterSetName='SetGlobalAuth', mandatory=$true)] |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Update an existing request item (RITM) |
| 5 | +
|
| 6 | + .DESCRIPTION |
| 7 | + Update an existing request item (RITM) |
| 8 | +
|
| 9 | + .EXAMPLE |
| 10 | + Update-ServiceNowRequestItem -SysId $SysId -Values @{property='value'} |
| 11 | +
|
| 12 | + Updates a ticket number with a value providing no return output. |
| 13 | +
|
| 14 | + .EXAMPLE |
| 15 | + Update-ServiceNowRequestItem -SysId $SysId -Values @{property='value'} -PassThru |
| 16 | +
|
| 17 | + Updates a ticket number with a value providing return output. |
| 18 | +
|
| 19 | + .NOTES |
| 20 | +
|
| 21 | + #> |
| 22 | + |
| 23 | + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidUsingConvertToSecureStringWithPlainText','')] |
| 24 | + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidGlobalVars','')] |
| 25 | + |
| 26 | + [OutputType([void],[System.Management.Automation.PSCustomObject])] |
| 27 | + [CmdletBinding(DefaultParameterSetName,SupportsShouldProcess=$true)] |
| 28 | + Param ( |
| 29 | + # sys_id of the ticket to update |
| 30 | + [Parameter(mandatory=$true)] |
8 | 31 | [string]$SysId, |
9 | 32 |
|
10 | | - # Hashtable of values to use as the record's properties |
11 | | - [parameter(mandatory=$true)] |
| 33 | + # Hashtable of values to use as the record's properties |
| 34 | + [Parameter(mandatory=$true)] |
12 | 35 | [hashtable]$Values, |
13 | 36 |
|
14 | | - # Credential used to authenticate to ServiceNow |
| 37 | + # Credential used to authenticate to ServiceNow |
15 | 38 | [Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)] |
16 | 39 | [ValidateNotNullOrEmpty()] |
17 | | - [PSCredential]$ServiceNowCredential, |
| 40 | + [Alias('ServiceNowCredential')] |
| 41 | + [PSCredential]$Credential, |
18 | 42 |
|
19 | 43 | # The URL for the ServiceNow instance being used (eg: instancename.service-now.com) |
20 | 44 | [Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)] |
21 | 45 | [ValidateNotNullOrEmpty()] |
22 | | - [string]$ServiceNowURL, |
| 46 | + [string]$ServiceNowURL, |
23 | 47 |
|
24 | 48 | #Azure Automation Connection object containing username, password, and URL for the ServiceNow instance |
25 | | - [Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)] |
| 49 | + [Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)] |
26 | 50 | [ValidateNotNullOrEmpty()] |
27 | | - [Hashtable]$Connection |
28 | | - ) |
| 51 | + [Hashtable]$Connection, |
| 52 | + |
| 53 | + # Switch to allow the results to be passed back |
| 54 | + [Parameter(Mandatory=$false)] |
| 55 | + [switch]$PassThru |
| 56 | + ) |
29 | 57 |
|
30 | 58 | $updateServiceNowTableEntrySplat = @{ |
31 | | - SysId = $SysId |
32 | | - Table = 'sc_req_item' |
| 59 | + SysId = $SysId |
| 60 | + Table = 'sc_req_item' |
33 | 61 | Values = $Values |
34 | 62 | } |
35 | | - |
| 63 | + |
36 | 64 | # Update the splat if the parameters have values |
37 | | - if ($null -ne $PSBoundParameters.Connection) |
38 | | - { |
| 65 | + If ($null -ne $PSBoundParameters.Connection) { |
39 | 66 | $updateServiceNowTableEntrySplat.Add('Connection',$Connection) |
40 | 67 | } |
41 | | - elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL) |
42 | | - { |
| 68 | + ElseIf ($null -ne $PSBoundParameters.Credential -and $null -ne $PSBoundParameters.ServiceNowURL) { |
43 | 69 | $updateServiceNowTableEntrySplat.Add('ServiceNowCredential',$ServiceNowCredential) |
44 | 70 | $updateServiceNowTableEntrySplat.Add('ServiceNowURL',$ServiceNowURL) |
45 | 71 | } |
46 | | - |
47 | | - Update-ServiceNowTableEntry @updateServiceNowTableEntrySplat |
48 | | -} |
49 | 72 |
|
| 73 | + If ($PSCmdlet.ShouldProcess("$Table/$SysID",$MyInvocation.MyCommand)) { |
| 74 | + # Send REST call |
| 75 | + $Result = Update-ServiceNowTableEntry @updateServiceNowTableEntrySplat |
| 76 | + |
| 77 | + # Option to return results |
| 78 | + If ($PSBoundParameters.ContainsKey('Passthru')) { |
| 79 | + $Result |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments