Skip to content

Commit 8f57ed7

Browse files
committed
attachment pipeline enhancements
1 parent ba5ad9d commit 8f57ed7

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.3.2
2+
- Added ability to pipe to `Add-ServiceNowAttachment` and `Get-ServiceNowAttachmentDetail`. For example, `New-ServiceNowIncident @params -PassThru | Add-ServiceNowAttachment -File MyFile.txt`. This will create an incident and add an attachment in one step.
3+
14
## 2.3.1
25
- Fix query operator -notin and -notlike which had a missing space
36
- Move verbose logging message in `Invoke-ServiceNowRestMethod` for number of records so it always shows. This is helpful when you change a filter and can see how many records would be returned without actually returning them.

ServiceNow/Public/Add-ServiceNowAttachment.ps1

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ Function Add-ServiceNowAttachment {
1717
1818
.EXAMPLE
1919
Add-ServiceNowAttachment -Number $Number -Table $Table -File .\File01.txt, .\File02.txt
20-
20+
2121
Upload one or more files to a ServiceNow ticket by specifing the number and table
2222
2323
.EXAMPLE
24-
Add-ServiceNowAttachment -Number $Number -Table $Table -File .\File01.txt -ContentType 'text/plain'
24+
New-ServiceNowIncident @params -PassThru | Add-ServiceNowAttachment -File File01.txt
25+
26+
Create a new incident and add an attachment
2527
28+
.EXAMPLE
29+
Add-ServiceNowAttachment -Number $Number -Table $Table -File .\File01.txt -ContentType 'text/plain'
30+
2631
Upload a file and specify the MIME type (content type). Should only be required if the function cannot automatically determine the type.
2732
2833
.EXAMPLE
@@ -31,23 +36,21 @@ Function Add-ServiceNowAttachment {
3136
Upload a file and receive back the file details.
3237
3338
.OUTPUTS
34-
System.Management.Automation.PSCustomObject
35-
36-
.NOTES
37-
39+
System.Management.Automation.PSCustomObject if -PassThru provided
3840
#>
3941

4042
[OutputType([PSCustomObject[]])]
4143
[CmdletBinding(DefaultParameterSetName = 'Session', SupportsShouldProcess)]
4244
Param(
43-
# Object number
44-
[Parameter(Mandatory)]
45-
[string] $Number,
46-
4745
# Table containing the entry
48-
[Parameter(Mandatory)]
46+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
47+
[Alias('sys_class_name')]
4948
[string]$Table,
5049

50+
# Object number
51+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
52+
[string] $Number,
53+
5154
# Filter results by file name
5255
[parameter(Mandatory)]
5356
[ValidateScript( {
@@ -92,7 +95,7 @@ Function Add-ServiceNowAttachment {
9295

9396
$getSysIdParams = @{
9497
Table = $Table
95-
Query = (New-ServiceNowQuery -MatchExact @{'number' = $number })
98+
Query = (New-ServiceNowQuery -Filter @('number', '-eq', $number))
9699
Properties = 'sys_id'
97100
Connection = $Connection
98101
Credential = $Credential

ServiceNow/Public/Get-ServiceNowAttachmentDetail.ps1

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,18 @@ Function Get-ServiceNowAttachmentDetail {
2727
2828
.OUTPUTS
2929
System.Management.Automation.PSCustomObject
30-
31-
.NOTES
32-
3330
#>
3431

3532
[OutputType([System.Management.Automation.PSCustomObject[]])]
3633
[CmdletBinding(DefaultParameterSetName)]
3734
Param(
3835
# Table containing the entry
39-
[Parameter(Mandatory)]
36+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
37+
[Alias('sys_class_name')]
4038
[string] $Table,
4139

4240
# Object number
43-
[Parameter(Mandatory)]
41+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
4442
[string] $Number,
4543

4644
# Filter results by file name
@@ -76,7 +74,7 @@ Function Get-ServiceNowAttachmentDetail {
7674

7775
$getSysIdParams = @{
7876
Table = $Table
79-
Query = (New-ServiceNowQuery -MatchExact @{'number' = $number })
77+
Query = (New-ServiceNowQuery -Filter @('number', '-eq', $number))
8078
Properties = 'sys_id'
8179
Connection = $Connection
8280
Credential = $Credential
@@ -89,10 +87,13 @@ Function Get-ServiceNowAttachmentDetail {
8987

9088
$params = @{
9189
Uri = '/attachment'
92-
Query = (New-ServiceNowQuery -MatchExact @{
93-
table_name = $Table
94-
table_sys_id = $sysId
95-
})
90+
Query = (
91+
New-ServiceNowQuery -Filter @(
92+
@('table_name', '-eq', $Table),
93+
'and',
94+
@('table_sys_id', '-eq', $sysId)
95+
)
96+
)
9697
Connection = $Connection
9798
Credential = $Credential
9899
ServiceNowUrl = $ServiceNowURL
@@ -101,10 +102,13 @@ Function Get-ServiceNowAttachmentDetail {
101102
$response = Invoke-ServiceNowRestMethod @params
102103

103104
if ( $FileName ) {
104-
$response = $response | Where-Object { $_.file_name -in $FileName }
105+
$response | Where-Object { $_.file_name -in $FileName }
106+
}
107+
else {
108+
$response
105109
}
106110

107-
$response | Update-ServiceNowDateTimeField
111+
# $response | Update-ServiceNowDateTimeField
108112
}
109113

110114
end {}

ServiceNow/ServiceNow.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CompanyName = 'None'
2020
Copyright = '(c) 2015-2021 Snow-Shell. All rights reserved.'
2121

2222
# Description of the functionality provided by this module
23-
Description = 'This module provides cmdlets allowing you to retrieve information from your ServiceNow instance''s REST API'
23+
Description = 'Automate against ServiceNow service and asset management. This module can be used standalone or with Azure Automation.'
2424

2525
# Minimum version of the Windows PowerShell engine required by this module
2626
# PowerShellVersion = '3.0'

0 commit comments

Comments
 (0)