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