Skip to content

Commit 98c53af

Browse files
committed
Add function Get-ServiceNowTableEntry
1 parent 6dcb406 commit 98c53af

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
function Get-ServiceNowTableEntry {
2+
<#
3+
.SYNOPSIS
4+
Wraps Get-ServiceNowQuery & Get-ServiceNowTable for easier custom table queries
5+
.DESCRIPTION
6+
Wraps Get-ServiceNowQuery & Get-ServiceNowTable for easier custom table queries. No formatting is provided on output. Every property is returned by default.
7+
.EXAMPLE
8+
Get-ServiceNowTableEntry -Table sc_req_item -Limit 1
9+
10+
Returns one request item (RITM) from the sc_req_item table
11+
.EXAMPLE
12+
$Record = Get-ServiceNowTableEntry -Table u_customtable -MatchExact {number=$Number}
13+
Update-ServiceNowTableEntry -SysID $Record.sys_id -Table u_customtable -Values {comments='Ticket updated'}
14+
15+
Utilize the returned object data with to provide the sys_id property required for updates and removals
16+
.OUTPUTS
17+
System.Management.Automation.PSCustomObject
18+
.NOTES
19+
20+
#>
21+
param(
22+
# Table containing the entry we're deleting
23+
[parameter(mandatory=$true)]
24+
[parameter(ParameterSetName='SpecifyConnectionFields')]
25+
[parameter(ParameterSetName='UseConnectionObject')]
26+
[parameter(ParameterSetName='SetGlobalAuth')]
27+
[string]$Table,
28+
29+
# Machine name of the field to order by
30+
[parameter(mandatory = $false)]
31+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
32+
[parameter(ParameterSetName = 'UseConnectionObject')]
33+
[parameter(ParameterSetName = 'SetGlobalAuth')]
34+
[string]$OrderBy = 'opened_at',
35+
36+
# Direction of ordering (Desc/Asc)
37+
[parameter(mandatory = $false)]
38+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
39+
[parameter(ParameterSetName = 'UseConnectionObject')]
40+
[parameter(ParameterSetName = 'SetGlobalAuth')]
41+
[ValidateSet("Desc", "Asc")]
42+
[string]$OrderDirection = 'Desc',
43+
44+
# Maximum number of records to return
45+
[parameter(mandatory = $false)]
46+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
47+
[parameter(ParameterSetName = 'UseConnectionObject')]
48+
[parameter(ParameterSetName = 'SetGlobalAuth')]
49+
[int]$Limit = 10,
50+
51+
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
52+
[parameter(mandatory = $false)]
53+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
54+
[parameter(ParameterSetName = 'UseConnectionObject')]
55+
[parameter(ParameterSetName = 'SetGlobalAuth')]
56+
[hashtable]$MatchExact = @{},
57+
58+
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
59+
[parameter(mandatory = $false)]
60+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
61+
[parameter(ParameterSetName = 'UseConnectionObject')]
62+
[parameter(ParameterSetName = 'SetGlobalAuth')]
63+
[hashtable]$MatchContains = @{},
64+
65+
# Whether or not to show human readable display values instead of machine values
66+
[parameter(mandatory = $false)]
67+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
68+
[parameter(ParameterSetName = 'UseConnectionObject')]
69+
[parameter(ParameterSetName = 'SetGlobalAuth')]
70+
[ValidateSet("true", "false", "all")]
71+
[string]$DisplayValues = 'true',
72+
73+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)]
74+
[ValidateNotNullOrEmpty()]
75+
[PSCredential]
76+
$ServiceNowCredential,
77+
78+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)]
79+
[ValidateNotNullOrEmpty()]
80+
[string]
81+
$ServiceNowURL,
82+
83+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $True)]
84+
[ValidateNotNullOrEmpty()]
85+
[Hashtable]
86+
$Connection
87+
)
88+
89+
# Query Splat
90+
$newServiceNowQuerySplat = @{
91+
OrderBy = $OrderBy
92+
MatchExact = $MatchExact
93+
OrderDirection = $OrderDirection
94+
MatchContains = $MatchContains
95+
}
96+
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
97+
98+
# Table Splat
99+
$getServiceNowTableSplat = @{
100+
Table = $Table
101+
Query = $Query
102+
Limit = $Limit
103+
DisplayValues = $DisplayValues
104+
}
105+
106+
# Update the Table Splat if the parameters have values
107+
if ($null -ne $PSBoundParameters.Connection) {
108+
$getServiceNowTableSplat.Add('Connection', $Connection)
109+
}
110+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL) {
111+
$getServiceNowTableSplat.Add('ServiceNowCredential', $ServiceNowCredential)
112+
$getServiceNowTableSplat.Add('ServiceNowURL', $ServiceNowURL)
113+
}
114+
115+
# Perform table query and return each object. No fancy formatting here as this can pull tables with unknown default properties
116+
Get-ServiceNowTable @getServiceNowTableSplat
117+
}

ServiceNow/ServiceNow.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ FormatsToProcess = @('ServiceNow.format.ps1xml')
6666
NestedModules = @()
6767

6868
# Functions to export from this module
69-
FunctionsToExport = @('Get-ServiceNowChangeRequest','Get-ServiceNowConfigurationItem','Get-ServiceNowIncident','Get-ServiceNowRequest','Get-ServiceNowTable','Get-ServiceNowUser','Get-ServiceNowUserGroup','New-ServiceNowIncident','New-ServiceNowQuery','New-ServiceNowTableEntry','Remove-ServiceNowAuth','Remove-ServiceNowTableEntry','Set-ServiceNowAuth','Test-ServiceNowAuthIsSet','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowTableEntry')
69+
FunctionsToExport = @('Get-ServiceNowChangeRequest','Get-ServiceNowConfigurationItem','Get-ServiceNowIncident','Get-ServiceNowRequest','Get-ServiceNowTable','Get-ServiceNowTableEntry''Get-ServiceNowUser','Get-ServiceNowUserGroup','New-ServiceNowIncident','New-ServiceNowQuery','New-ServiceNowTableEntry','Remove-ServiceNowAuth','Remove-ServiceNowTableEntry','Set-ServiceNowAuth','Test-ServiceNowAuthIsSet','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowTableEntry')
7070

7171
# List of all modules packaged with this module
7272
# ModuleList = @()

0 commit comments

Comments
 (0)