|
| 1 | +function Get-ServiceNowRequestItem { |
| 2 | +<# |
| 3 | + .SYNOPSIS |
| 4 | + Query for Request Item (RITM) tickets. |
| 5 | +
|
| 6 | + .DESCRIPTION |
| 7 | + Query for Request Item (RITM) tickets from the sc_req_item table. |
| 8 | +
|
| 9 | + .EXAMPLE |
| 10 | + Get-ServiceNowRequestItem -MatchExact @{number='RITM0000001'} |
| 11 | +
|
| 12 | + Return the details for RITM0000001 |
| 13 | +
|
| 14 | + .OUTPUTS |
| 15 | + System.Management.Automation.PSCustomObject |
| 16 | +#> |
| 17 | + |
| 18 | + [OutputType([System.Management.Automation.PSCustomObject])] |
| 19 | + [CmdletBinding(DefaultParameterSetName)] |
| 20 | + param( |
| 21 | + # Machine name of the field to order by |
| 22 | + [parameter(Mandatory = $false)] |
| 23 | + [string]$OrderBy = 'opened_at', |
| 24 | + |
| 25 | + # Direction of ordering (Desc/Asc) |
| 26 | + [parameter(Mandatory = $false)] |
| 27 | + [ValidateSet('Desc', 'Asc')] |
| 28 | + [string]$OrderDirection = 'Desc', |
| 29 | + |
| 30 | + # Maximum number of records to return |
| 31 | + [parameter(Mandatory = $false)] |
| 32 | + [int]$Limit = 10, |
| 33 | + |
| 34 | + # Hashtable containing machine field names and values returned must match exactly (will be combined with AND) |
| 35 | + [parameter(Mandatory = $false)] |
| 36 | + [hashtable]$MatchExact = @{}, |
| 37 | + |
| 38 | + # Hashtable containing machine field names and values returned rows must contain (will be combined with AND) |
| 39 | + [parameter(Mandatory = $false)] |
| 40 | + [hashtable]$MatchContains = @{}, |
| 41 | + |
| 42 | + # Whether or not to show human readable display values instead of machine values |
| 43 | + [parameter(Mandatory = $false)] |
| 44 | + [ValidateSet('true', 'false', 'all')] |
| 45 | + [string]$DisplayValues = 'true', |
| 46 | + |
| 47 | + [Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)] |
| 48 | + [ValidateNotNullOrEmpty()] |
| 49 | + [Alias('ServiceNowCredential')] |
| 50 | + [PSCredential]$Credential, |
| 51 | + |
| 52 | + [Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)] |
| 53 | + [ValidateNotNullOrEmpty()] |
| 54 | + [string]$ServiceNowURL, |
| 55 | + |
| 56 | + [Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $True)] |
| 57 | + [ValidateNotNullOrEmpty()] |
| 58 | + [hashtable]$Connection |
| 59 | + ) |
| 60 | + |
| 61 | + # Query Splat |
| 62 | + $newServiceNowQuerySplat = @{ |
| 63 | + OrderBy = $OrderBy |
| 64 | + MatchExact = $MatchExact |
| 65 | + OrderDirection = $OrderDirection |
| 66 | + MatchContains = $MatchContains |
| 67 | + } |
| 68 | + $Query = New-ServiceNowQuery @newServiceNowQuerySplat |
| 69 | + |
| 70 | + # Table Splat |
| 71 | + $getServiceNowTableSplat = @{ |
| 72 | + Table = 'sc_req_item' |
| 73 | + Query = $Query |
| 74 | + Limit = $Limit |
| 75 | + DisplayValues = $DisplayValues |
| 76 | + } |
| 77 | + |
| 78 | + # Update the Table Splat if the parameters have values |
| 79 | + if ($null -ne $PSBoundParameters.Connection) { |
| 80 | + $getServiceNowTableSplat.Add('Connection', $Connection) |
| 81 | + } |
| 82 | + elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL) { |
| 83 | + $getServiceNowTableSplat.Add('ServiceNowCredential', $ServiceNowCredential) |
| 84 | + $getServiceNowTableSplat.Add('ServiceNowURL', $ServiceNowURL) |
| 85 | + } |
| 86 | + |
| 87 | + # Perform query and return each object in the format.ps1xml format |
| 88 | + $Result = Get-ServiceNowTable @getServiceNowTableSplat |
| 89 | + $Result | ForEach-Object {$_.PSObject.TypeNames.Insert(0,'ServiceNow.Request')} |
| 90 | + $Result |
| 91 | +} |
0 commit comments