Skip to content

Commit 366b795

Browse files
committed
combine old gets, prep for deprecation
1 parent f84667d commit 366b795

File tree

4 files changed

+191
-8
lines changed

4 files changed

+191
-8
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
function Get-ServiceNowRecordInterim {
2+
[OutputType([System.Management.Automation.PSCustomObject])]
3+
[CmdletBinding(DefaultParameterSetName = 'Session', SupportsPaging)]
4+
Param(
5+
# Machine name of the field to order by
6+
[Parameter()]
7+
[string] $OrderBy = 'opened_at',
8+
9+
# Direction of ordering (Desc/Asc)
10+
[Parameter()]
11+
[ValidateSet('Desc', 'Asc')]
12+
[string] $OrderDirection = 'Desc',
13+
14+
# Fields to return
15+
[Parameter()]
16+
[Alias('Fields', 'Properties')]
17+
[string[]] $Property,
18+
19+
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
20+
[Parameter()]
21+
[hashtable] $MatchExact = @{},
22+
23+
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
24+
[Parameter()]
25+
[hashtable] $MatchContains = @{},
26+
27+
# Whether or not to show human readable display values instead of machine values
28+
[Parameter()]
29+
[ValidateSet('true', 'false', 'all')]
30+
[Alias('DisplayValues')]
31+
[string] $DisplayValue = 'true',
32+
33+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory)]
34+
[ValidateNotNullOrEmpty()]
35+
[hashtable] $Connection,
36+
37+
[Parameter(ParameterSetName = 'Session')]
38+
[ValidateNotNullOrEmpty()]
39+
[hashtable] $ServiceNowSession = $script:ServiceNowSession
40+
)
41+
42+
Write-Warning ('{0} will be deprecated in the near future. Please use Get-ServiceNowRecord instead.' -f $PSCmdlet.MyInvocation.InvocationName)
43+
44+
$table = $ServiceNowTable | Where-Object { $PSCmdlet.MyInvocation.InvocationName.ToLower().Replace('get-servicenow', '') -eq $_.ClassName.Replace(' ', '').ToLower() }
45+
46+
$newServiceNowQuerySplat = @{
47+
OrderBy = $OrderBy
48+
MatchExact = $MatchExact
49+
OrderDirection = $OrderDirection
50+
MatchContains = $MatchContains
51+
}
52+
$query = New-ServiceNowQuery @newServiceNowQuerySplat
53+
54+
$params = @{
55+
Table = $table.Name
56+
Query = $query
57+
DisplayValue = $DisplayValue
58+
First = $PSCmdlet.PagingParameters.First
59+
Skip = $PSCmdlet.PagingParameters.Skip
60+
IncludeTotalCount = $PSCmdlet.PagingParameters.IncludeTotalCount
61+
Connection = $Connection
62+
ServiceNowSession = $ServiceNowSession
63+
}
64+
$result = Invoke-ServiceNowRestMethod @params
65+
66+
If ( $result -and -not $Properties) {
67+
$result | ForEach-Object { $_.PSObject.TypeNames.Insert(0, $table.Type) }
68+
}
69+
$result
70+
}

ServiceNow/ServiceNow.format.ps1xml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,5 +375,102 @@
375375
</TableRowEntries>
376376
</TableControl>
377377
</View>
378+
<View>
379+
<Name>ServiceNow.ChangeTask</Name>
380+
<ViewSelectedBy>
381+
<TypeName>ServiceNow.ChangeTask</TypeName>
382+
</ViewSelectedBy>
383+
<TableControl>
384+
<TableHeaders>
385+
<TableColumnHeader>
386+
<Label>number</Label>
387+
<Width>12</Width>
388+
</TableColumnHeader>
389+
<TableColumnHeader>
390+
<Label>state</Label>
391+
<Width>10</Width>
392+
</TableColumnHeader>
393+
<TableColumnHeader>
394+
<Label>opened_at</Label>
395+
<Width>21</Width>
396+
</TableColumnHeader>
397+
<TableColumnHeader>
398+
<Label>short_description</Label>
399+
<Width>25</Width>
400+
</TableColumnHeader>
401+
<TableColumnHeader>
402+
<Label>change_request</Label>
403+
<Width>15</Width>
404+
</TableColumnHeader>
405+
</TableHeaders>
406+
<TableRowEntries>
407+
<TableRowEntry>
408+
<TableColumnItems>
409+
<TableColumnItem>
410+
<PropertyName>number</PropertyName>
411+
</TableColumnItem>
412+
<TableColumnItem>
413+
<PropertyName>state</PropertyName>
414+
</TableColumnItem>
415+
<TableColumnItem>
416+
<PropertyName>opened_at</PropertyName>
417+
</TableColumnItem>
418+
<TableColumnItem>
419+
<PropertyName>short_description</PropertyName>
420+
</TableColumnItem>
421+
<TableColumnItem>
422+
<ScriptBlock>
423+
$_.change_request.display_value
424+
</ScriptBlock>
425+
</TableColumnItem>
426+
</TableColumnItems>
427+
</TableRowEntry>
428+
</TableRowEntries>
429+
</TableControl>
430+
</View>
431+
<View>
432+
<Name>ServiceNow.Attachment</Name>
433+
<ViewSelectedBy>
434+
<TypeName>ServiceNow.Attachment</TypeName>
435+
</ViewSelectedBy>
436+
<TableControl>
437+
<TableHeaders>
438+
<TableColumnHeader>
439+
<Label>file_name</Label>
440+
<Width>25</Width>
441+
</TableColumnHeader>
442+
<TableColumnHeader>
443+
<Label>size_bytes</Label>
444+
<Width>15</Width>
445+
</TableColumnHeader>
446+
<TableColumnHeader>
447+
<Label>table_name</Label>
448+
<Width>20</Width>
449+
</TableColumnHeader>
450+
<TableColumnHeader>
451+
<Label>table_sys_id</Label>
452+
<Width>32</Width>
453+
</TableColumnHeader>
454+
</TableHeaders>
455+
<TableRowEntries>
456+
<TableRowEntry>
457+
<TableColumnItems>
458+
<TableColumnItem>
459+
<PropertyName>file_name</PropertyName>
460+
</TableColumnItem>
461+
<TableColumnItem>
462+
<PropertyName>size_bytes</PropertyName>
463+
</TableColumnItem>
464+
<TableColumnItem>
465+
<PropertyName>table_name</PropertyName>
466+
</TableColumnItem>
467+
<TableColumnItem>
468+
<PropertyName>table_sys_id</PropertyName>
469+
</TableColumnItem>
470+
</TableColumnItems>
471+
</TableRowEntry>
472+
</TableRowEntries>
473+
</TableControl>
474+
</View>
378475
</ViewDefinitions>
379476
</Configuration>

ServiceNow/ServiceNow.psd1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ FormatsToProcess = @('ServiceNow.format.ps1xml')
5959
NestedModules = @()
6060

6161
# Functions to export from this module
62-
FunctionsToExport = @('New-ServiceNowConfigurationItem','Get-ServiceNowRecord','New-ServiceNowSession','Add-ServiceNowAttachment','Get-ServiceNowAttachment','Get-ServiceNowAttachmentDetail','Get-ServiceNowChangeRequest','Get-ServiceNowConfigurationItem','Get-ServiceNowIncident','Get-ServiceNowRequest','Get-ServiceNowRequestedItem','Get-ServiceNowTable','Get-ServiceNowTableEntry','Get-ServiceNowUser','Get-ServiceNowUserGroup','New-ServiceNowChangeRequest','New-ServiceNowIncident','New-ServiceNowQuery','New-ServiceNowRecord','Remove-ServiceNowAttachment','Remove-ServiceNowAuth','Remove-ServiceNowRecord','Set-ServiceNowAuth','Test-ServiceNowAuthIsSet','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowNumber','Update-ServiceNowRequestItem','Update-ServiceNowRecord')
62+
FunctionsToExport = @('Get-ServiceNowRecordInterim','New-ServiceNowConfigurationItem','Get-ServiceNowRecord','New-ServiceNowSession','Add-ServiceNowAttachment','Get-ServiceNowAttachment','Export-ServiceNowAttachment','Get-ServiceNowChangeRequest','Get-ServiceNowConfigurationItem','Get-ServiceNowIncident','Get-ServiceNowRequest','Get-ServiceNowRequestedItem','Get-ServiceNowTable','Get-ServiceNowTableEntry','Get-ServiceNowUser','Get-ServiceNowUserGroup','New-ServiceNowChangeRequest','New-ServiceNowIncident','New-ServiceNowQuery','New-ServiceNowRecord','Remove-ServiceNowAttachment','Remove-ServiceNowAuth','Remove-ServiceNowRecord','Set-ServiceNowAuth','Test-ServiceNowAuthIsSet','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowNumber','Update-ServiceNowRequestItem','Update-ServiceNowRecord')
6363

6464
# Variables to export from this module
65-
VariablesToExport = 'ServiceNowSession', 'ServiceNowOperator', 'ServiceNowTable'
65+
VariablesToExport = @('ServiceNowSession', 'ServiceNowOperator', 'ServiceNowTable')
66+
67+
AliasesToExport = @('gsnr','Get-ServiceNowIncident','Get-ServiceNowChangeRequest', 'Get-ServiceNowConfigurationItem', 'Get-ServiceNowRequest', 'Get-ServiceNowRequestedItem', 'Get-ServiceNowUser', 'Get-ServiceNowUserGroup')
6668

6769
# List of all modules packaged with this module
6870
# ModuleList = @()

ServiceNow/ServiceNow.psm1

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ $tableArgCompleterSb = {
1515
}
1616
}
1717

18-
Register-ArgumentCompleter -CommandName 'Get-ServiceNowRecord' -ParameterName 'Table' -ScriptBlock $tableArgCompleterSb
18+
# assign the table arg completer to functions
19+
@(
20+
'Get-ServiceNowRecord',
21+
'Get-ServiceNowAttachment'
22+
) | ForEach-Object {
23+
Register-ArgumentCompleter -CommandName $_ -ParameterName 'Table' -ScriptBlock $tableArgCompleterSb
24+
}
1925

2026
Write-Verbose 'Import everything in sub folders folder'
2127
foreach ($Folder in @('Private', 'Public')) {
@@ -36,11 +42,19 @@ $Script:ServiceNowSession = @{}
3642
Export-ModuleMember -Variable ServiceNowSession
3743

3844
$aliases = @{
39-
'Get-ServiceNowRequestItem' = 'Get-ServiceNowRequestedItem'
40-
'Update-ServiceNowRequestItem' = 'Update-ServiceNowRequestedItem'
41-
'Remove-ServiceNowTableEntry' = 'Remove-ServiceNowRecord'
42-
'New-ServiceNowTableEntry' = 'New-ServiceNowRecord'
43-
'Update-ServiceNowTableEntry' = 'Update-ServiceNowRecord'
45+
'Get-ServiceNowRequestItem' = 'Get-ServiceNowRequestedItem'
46+
'Get-ServiceNowIncident' = 'Get-ServiceNowRecordInterim'
47+
'Get-ServiceNowChangeRequest' = 'Get-ServiceNowRecordInterim'
48+
'Get-ServiceNowConfigurationItem' = 'Get-ServiceNowRecordInterim'
49+
'Get-ServiceNowRequest' = 'Get-ServiceNowRecordInterim'
50+
'Get-ServiceNowRequestedItem' = 'Get-ServiceNowRecordInterim'
51+
'Get-ServiceNowUser' = 'Get-ServiceNowRecordInterim'
52+
'Get-ServiceNowUserGroup' = 'Get-ServiceNowRecordInterim'
53+
'Update-ServiceNowRequestItem' = 'Update-ServiceNowRequestedItem'
54+
'Remove-ServiceNowTableEntry' = 'Remove-ServiceNowRecord'
55+
'New-ServiceNowTableEntry' = 'New-ServiceNowRecord'
56+
'Update-ServiceNowTableEntry' = 'Update-ServiceNowRecord'
57+
'gsnr' = 'Get-ServiceNowRecord'
4458
}
4559
$aliases.GetEnumerator() | ForEach-Object {
4660
Set-Alias -Name $_.Key -Value $_.Value

0 commit comments

Comments
 (0)