Skip to content

Commit e360826

Browse files
committed
deprecation warning, update cleanup
1 parent 0c43822 commit e360826

File tree

6 files changed

+76
-125
lines changed

6 files changed

+76
-125
lines changed

ServiceNow/Public/Get-ServiceNowRecord.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
Name of the table to be queried, by either table name or class name. Use tab completion for list of known tables.
1212
You can also provide any table name ad hoc.
1313
14+
.PARAMETER Id
15+
Either the record sys_id or number.
16+
If providing just an Id, not with Table, the Id prefix will be looked up to find the table name.
17+
18+
.PARAMETER Name
19+
1420
.PARAMETER Property
1521
Limit the fields returned to this list
1622
@@ -121,16 +127,9 @@ function Get-ServiceNowRecord {
121127
[Parameter()]
122128
[switch] $IncludeCustomVariable,
123129

124-
# [Parameter(Mandatory, ParameterSetName = 'AutomationTable')]
125-
# [Parameter(Mandatory, ParameterSetName = 'AutomationId')]
126-
# [ValidateNotNullOrEmpty()]
127-
# [AllowNull()]
128130
[Parameter()]
129131
[hashtable] $Connection,
130132

131-
# [Parameter(ParameterSetName = 'SessionTable')]
132-
# [Parameter(ParameterSetName = 'SessionId')]
133-
# [ValidateNotNullOrEmpty()]
134133
[Parameter()]
135134
[hashtable] $ServiceNowSession = $script:ServiceNowSession
136135
)

ServiceNow/Public/Get-ServiceNowRecordInterim.ps1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function Get-ServiceNowRecordInterim {
22
[OutputType([System.Management.Automation.PSCustomObject])]
3-
[CmdletBinding(DefaultParameterSetName = 'Session', SupportsPaging)]
3+
[CmdletBinding(SupportsPaging)]
44
Param(
55
# Machine name of the field to order by
66
[Parameter()]
@@ -30,17 +30,15 @@ function Get-ServiceNowRecordInterim {
3030
[Alias('DisplayValues')]
3131
[string] $DisplayValue = 'true',
3232

33-
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory)]
34-
[ValidateNotNullOrEmpty()]
33+
[Parameter()]
3534
[hashtable] $Connection,
3635

37-
[Parameter(ParameterSetName = 'Session')]
38-
[ValidateNotNullOrEmpty()]
36+
[Parameter()]
3937
[hashtable] $ServiceNowSession = $script:ServiceNowSession
4038
)
4139

4240
Write-Warning ('{0} will be deprecated in the near future. Please use Get-ServiceNowRecord instead.' -f $PSCmdlet.MyInvocation.InvocationName)
43-
41+
4442
$table = $ServiceNowTable | Where-Object { $PSCmdlet.MyInvocation.InvocationName.ToLower().Replace('get-servicenow', '') -eq $_.ClassName.Replace(' ', '').ToLower() }
4543

4644
$newServiceNowQuerySplat = @{
@@ -49,11 +47,10 @@ function Get-ServiceNowRecordInterim {
4947
OrderDirection = $OrderDirection
5048
MatchContains = $MatchContains
5149
}
52-
$query = New-ServiceNowQuery @newServiceNowQuerySplat
5350

5451
$params = @{
5552
Table = $table.Name
56-
Query = $query
53+
Query = (New-ServiceNowQuery @newServiceNowQuerySplat)
5754
DisplayValue = $DisplayValue
5855
First = $PSCmdlet.PagingParameters.First
5956
Skip = $PSCmdlet.PagingParameters.Skip

ServiceNow/Public/Update-ServiceNowNumber.ps1

Lines changed: 0 additions & 85 deletions
This file was deleted.

ServiceNow/Public/Update-ServiceNowRecord.ps1

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,90 @@
11
function Update-ServiceNowRecord {
2-
[CmdletBinding(DefaultParameterSetName = 'SessionSysId', SupportsShouldProcess)]
2+
3+
<#
4+
.SYNOPSIS
5+
Update record values
6+
.DESCRIPTION
7+
Update one or more record values and optionally return the updated record
8+
.EXAMPLE
9+
PS C:\> <example usage>
10+
Explanation of what the example does
11+
.INPUTS
12+
Inputs (if any)
13+
.OUTPUTS
14+
Output (if any)
15+
.NOTES
16+
General notes
17+
#>
18+
19+
[CmdletBinding(SupportsShouldProcess)]
20+
321
Param(
422
# Table containing the entry we're updating
5-
[parameter(Mandatory)]
23+
[parameter(ValueFromPipelineByPropertyName)]
624
[Alias('sys_class_name')]
725
[string] $Table,
826

9-
[Parameter(ParameterSetName = 'AutomationSysId', Mandatory, ValueFromPipelineByPropertyName)]
10-
[Parameter(ParameterSetName = 'SessionSysId', Mandatory, ValueFromPipelineByPropertyName)]
11-
[Alias('sys_id')]
12-
[string] $SysId,
13-
14-
[Parameter(ParameterSetName = 'AutomationNumber', Mandatory)]
15-
[Parameter(ParameterSetName = 'SessionNumber', Mandatory)]
16-
[string] $Number,
27+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
28+
[Alias('sys_id', 'SysId', 'number')]
29+
[string] $Id,
1730

1831
# Hashtable of values to use as the record's properties
19-
[parameter()]
32+
[parameter(Mandatory)]
2033
[hashtable] $Values,
2134

22-
[Parameter(ParameterSetName = 'AutomationSysId', Mandatory)]
23-
[Parameter(ParameterSetName = 'AutomationNumber', Mandatory)]
24-
[ValidateNotNullOrEmpty()]
25-
[Hashtable] $Connection,
35+
[Parameter()]
36+
[switch] $PassThru,
2637

27-
[Parameter(ParameterSetName = 'SessionSysId')]
28-
[Parameter(ParameterSetName = 'SessionNumber')]
29-
[ValidateNotNullOrEmpty()]
30-
[hashtable] $ServiceNowSession = $script:ServiceNowSession,
38+
[Parameter()]
39+
[Hashtable] $Connection,
3140

3241
[Parameter()]
33-
[switch] $PassThru
42+
[hashtable] $ServiceNowSession = $script:ServiceNowSession
3443
)
3544

3645
begin {}
3746

3847
process {
48+
49+
if ( $Table -and ($Id -match '[a-zA-Z0-9]{32}') ) {
50+
# we already have table name and sys_id, no more to do before update
51+
$tableName = $Table
52+
$sysId = $Id
53+
}
54+
else {
55+
# get needed details, table name and sys_id, for update
56+
$getParams = @{
57+
Id = $Id
58+
Property = 'sys_class_name', 'sys_id', 'number'
59+
Connection = $Connection
60+
ServiceNowSession = $ServiceNowSession
61+
}
62+
63+
if ( $Table ) {
64+
$getParams.Table = $Table
65+
}
66+
67+
$thisRecord = Get-ServiceNowRecord @getParams
68+
69+
if ( $thisRecord ) {
70+
$tableName = $thisRecord.sys_class_name
71+
$sysId = $thisRecord.sys_id
72+
}
73+
else {
74+
throw ('Record not found for Id ''{0}''' -f $Id)
75+
}
76+
}
77+
3978
$params = @{
4079
Method = 'Patch'
41-
Table = $Table
42-
SysId = $SysId
80+
Table = $tableName
81+
SysId = $sysId
4382
Values = $Values
4483
Connection = $Connection
4584
ServiceNowSession = $ServiceNowSession
4685
}
4786

48-
If ($PSCmdlet.ShouldProcess("$Table $SysID", 'Update values')) {
87+
If ($PSCmdlet.ShouldProcess("$tableName $sysId", 'Update values')) {
4988
$response = Invoke-ServiceNowRestMethod @params
5089
if ( $PassThru.IsPresent ) {
5190
$response

ServiceNow/ServiceNow.psd1

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

6161
# Functions to export from this module
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')
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-ServiceNowRecord','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowRequestedItem','Update-ServiceNowRecord')
6363

6464
# Variables to export from this module
6565
VariablesToExport = @('ServiceNowSession', 'ServiceNowOperator', 'ServiceNowTable')
6666

67-
AliasesToExport = @('gsnr','Get-ServiceNowIncident','Get-ServiceNowChangeRequest', 'Get-ServiceNowConfigurationItem', 'Get-ServiceNowRequest', 'Get-ServiceNowRequestedItem', 'Get-ServiceNowUser', 'Get-ServiceNowUserGroup')
67+
AliasesToExport = @('gsnr','Get-ServiceNowIncident','Get-ServiceNowChangeRequest', 'Get-ServiceNowConfigurationItem', 'Get-ServiceNowRequest', 'Get-ServiceNowRequestedItem', 'Get-ServiceNowUser', 'Get-ServiceNowUserGroup','Update-ServiceNowNumber')
6868

6969
# List of all modules packaged with this module
7070
# ModuleList = @()

ServiceNow/ServiceNow.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ $aliases = @{
5454
'Remove-ServiceNowTableEntry' = 'Remove-ServiceNowRecord'
5555
'New-ServiceNowTableEntry' = 'New-ServiceNowRecord'
5656
'Update-ServiceNowTableEntry' = 'Update-ServiceNowRecord'
57+
'Update-ServiceNowNumber' = 'Update-ServiceNowRecord'
5758
'gsnr' = 'Get-ServiceNowRecord'
5859
}
5960
$aliases.GetEnumerator() | ForEach-Object {

0 commit comments

Comments
 (0)