11
22Function Get-ServiceNowAttachment {
33 <#
4-
4+
55 . SYNOPSIS
66 Retrieve attachment details
7-
7+
88 . DESCRIPTION
99 Retrieve attachment details via table record or by advanced filtering.
10-
10+
1111 . PARAMETER Table
1212 Name of the table to be queried, by either table name or class name. Use tab completion for list of known tables.
1313 You can also provide any table name ad hoc.
14-
14+
1515 . PARAMETER Id
1616 Either the record sys_id or number.
1717 If providing just an Id, not with Table, the Id prefix will be looked up to find the table name.
18-
18+
1919 . PARAMETER FileName
2020 Filter for a specific file name or part of a file name.
21-
21+
2222 . PARAMETER Filter
2323 Array or multidimensional array of fields and values to filter on.
2424 Each array should be of the format @(field, comparison operator, value) separated by a join, either 'and', 'or', or 'group'.
@@ -39,19 +39,19 @@ Function Get-ServiceNowAttachment {
3939
4040 . EXAMPLE
4141 Get-ServiceNowAttachment -Id 'INC1234567'
42-
42+
4343 Get attachment details for a specific record
44-
44+
4545 . EXAMPLE
4646 Get-ServiceNowAttachment -Id 'INC1234567' -FileName image.jpg
47-
47+
4848 Get attachment details for a specific record where file names match all or part of image.jpg
49-
49+
5050 . EXAMPLE
5151 Get-ServiceNowAttachment -Filter @('size_bytes', '-gt', '1000000')
52-
52+
5353 Get attachment details where size is greater than 1M.
54-
54+
5555 . INPUTS
5656 Table, Id
5757
@@ -112,17 +112,20 @@ Function Get-ServiceNowAttachment {
112112 $getParams.Table = $Table
113113 }
114114 $tableRecord = Get-ServiceNowRecord @getParams
115-
115+
116116 if ( -not $tableRecord ) {
117117 Write-Error " Record not found for Id '$Id '"
118118 continue
119119 }
120-
121- $params.Filter = @ (
122- @ (' table_name' , ' -eq' , $tableRecord.sys_class_name ),
123- ' and' ,
124- @ (' table_sys_id' , ' -eq' , $tableRecord.sys_id )
125- )
120+
121+ # perform lookup for known table names which might be different than sys_class_name
122+ $tableName = $script :ServiceNowTable | Where-Object { $_.Name.ToLower () -eq $tableRecord.sys_class_name.ToLower () -or $_.ClassName.ToLower () -eq $tableRecord.sys_class_name.ToLower () } | Select-Object - ExpandProperty Name
123+ if ( $tableName ) {
124+ $params.Filter = @ (@ (' table_name' , ' -eq' , $tableName ), ' and' , @ (' table_sys_id' , ' -eq' , $tableRecord.sys_id ))
125+ }
126+ else {
127+ $params.Filter = @ (@ (' table_name' , ' -eq' , $tableRecord.sys_class_name ), ' and' , @ (' table_sys_id' , ' -eq' , $tableRecord.sys_id ))
128+ }
126129 }
127130
128131 if ( $FileName ) {
0 commit comments