Skip to content

Commit 28e8db0

Browse files
authored
asvalue for gsnr (#179)
1 parent 28cded0 commit 28e8db0

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

RELEASE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
- Add `AsValue` parameter to `Export-ServiceNowAttachment` to return attachment contents instead of writing to a file
1+
- Add `AsValue` parameter to `Get-ServiceNowRecord` to return the underlying value for a property instead of a pscustomobject. Get your sys_id directly!
2+
- Add formatting for Unique Certificate (cmdb_ci_certificate) table

ServiceNow/Public/Get-ServiceNowRecord.ps1

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
For instance, an RITM may have custom variables, but the associated tasks may not.
5050
A property named 'CustomVariable' will be added to the return object.
5151
52+
.PARAMETER AsValue
53+
Return the underlying value instead of pscustomobject.
54+
Only valid when the Property parameter is set to 1 item.
55+
Helpful when retrieving sys_id for example.
56+
5257
.PARAMETER Connection
5358
Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
5459
@@ -105,6 +110,10 @@
105110
Get-ServiceNowRecord -Table 'change request' -IncludeCustomVariable -First 5
106111
Get the first 5 change requests and retrieve custom variable info
107112
113+
.EXAMPLE
114+
Get-ServiceNowRecord -Table 'cmdb_ci' -Property sys_id -First 1 -AsValue
115+
Get the underlying value for a property instead of a pscustomobject where the value needs to be extracted
116+
108117
.EXAMPLE
109118
gsnr RITM0010001
110119
Get a specific record by number using the function alias
@@ -175,6 +184,9 @@ function Get-ServiceNowRecord {
175184
[Parameter()]
176185
[switch] $IncludeCustomVariable,
177186

187+
[Parameter()]
188+
[switch] $AsValue,
189+
178190
[Parameter()]
179191
[hashtable] $Connection,
180192

@@ -336,12 +348,20 @@ function Get-ServiceNowRecord {
336348
else {
337349

338350
# format the results
339-
if ( -not $Property ) {
351+
if ( $Property ) {
352+
if ( $Property.Count -eq 1 -and $AsValue ) {
353+
$result | Select-Object -ExpandProperty $result.PSObject.Properties.Name
354+
}
355+
else {
356+
$result
357+
}
358+
}
359+
else {
340360
if ($thisTable.Type) {
341361
$result | ForEach-Object { $_.PSObject.TypeNames.Insert(0, $thisTable.Type) }
342362
}
363+
$result
343364
}
344-
$result
345365
}
346366
}
347367
}

ServiceNow/ServiceNow.format.ps1xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,5 +472,62 @@
472472
</TableRowEntries>
473473
</TableControl>
474474
</View>
475+
<View>
476+
<Name>ServiceNow.UniqueCertificate</Name>
477+
<ViewSelectedBy>
478+
<TypeName>ServiceNow.UniqueCertificate</TypeName>
479+
</ViewSelectedBy>
480+
<TableControl>
481+
<TableHeaders>
482+
<TableColumnHeader>
483+
<Label>name</Label>
484+
<Width>30</Width>
485+
</TableColumnHeader>
486+
<TableColumnHeader>
487+
<Label>valid_to</Label>
488+
<Width>20</Width>
489+
</TableColumnHeader>
490+
<TableColumnHeader>
491+
<Label>state</Label>
492+
<Width>15</Width>
493+
</TableColumnHeader>
494+
<TableColumnHeader>
495+
<Label>issuer</Label>
496+
<Width>30</Width>
497+
</TableColumnHeader>
498+
<TableColumnHeader>
499+
<Label>sys_id</Label>
500+
<Width>32</Width>
501+
</TableColumnHeader>
502+
</TableHeaders>
503+
<TableRowEntries>
504+
<TableRowEntry>
505+
<TableColumnItems>
506+
<TableColumnItem>
507+
<PropertyName>name</PropertyName>
508+
</TableColumnItem>
509+
<TableColumnItem>
510+
<PropertyName>valid_to</PropertyName>
511+
</TableColumnItem>
512+
<TableColumnItem>
513+
<PropertyName>state</PropertyName>
514+
</TableColumnItem>
515+
<TableColumnItem>
516+
<ScriptBlock>
517+
if ($_.issuer.display_value) {
518+
$_.issuer.display_value
519+
} else {
520+
$_.issuer.value
521+
}
522+
</ScriptBlock>
523+
</TableColumnItem>
524+
<TableColumnItem>
525+
<PropertyName>sys_id</PropertyName>
526+
</TableColumnItem>
527+
</TableColumnItems>
528+
</TableRowEntry>
529+
</TableRowEntries>
530+
</TableControl>
531+
</View>
475532
</ViewDefinitions>
476533
</Configuration>

0 commit comments

Comments
 (0)