1
1
2
2
Function Get-ServiceNowAttachment {
3
3
<#
4
-
4
+
5
5
. SYNOPSIS
6
6
Retrieve attachment details
7
-
7
+
8
8
. DESCRIPTION
9
9
Retrieve attachment details via table record or by advanced filtering.
10
-
10
+
11
11
. PARAMETER Table
12
12
Name of the table to be queried, by either table name or class name. Use tab completion for list of known tables.
13
13
You can also provide any table name ad hoc.
14
-
14
+
15
15
. PARAMETER Id
16
16
Either the record sys_id or number.
17
17
If providing just an Id, not with Table, the Id prefix will be looked up to find the table name.
18
-
18
+
19
19
. PARAMETER FileName
20
20
Filter for a specific file name or part of a file name.
21
-
21
+
22
22
. PARAMETER Filter
23
23
Array or multidimensional array of fields and values to filter on.
24
24
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 {
39
39
40
40
. EXAMPLE
41
41
Get-ServiceNowAttachment -Id 'INC1234567'
42
-
42
+
43
43
Get attachment details for a specific record
44
-
44
+
45
45
. EXAMPLE
46
46
Get-ServiceNowAttachment -Id 'INC1234567' -FileName image.jpg
47
-
47
+
48
48
Get attachment details for a specific record where file names match all or part of image.jpg
49
-
49
+
50
50
. EXAMPLE
51
51
Get-ServiceNowAttachment -Filter @('size_bytes', '-gt', '1000000')
52
-
52
+
53
53
Get attachment details where size is greater than 1M.
54
-
54
+
55
55
. INPUTS
56
56
Table, Id
57
57
@@ -112,17 +112,20 @@ Function Get-ServiceNowAttachment {
112
112
$getParams.Table = $Table
113
113
}
114
114
$tableRecord = Get-ServiceNowRecord @getParams
115
-
115
+
116
116
if ( -not $tableRecord ) {
117
117
Write-Error " Record not found for Id '$Id '"
118
118
continue
119
119
}
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
+ }
126
129
}
127
130
128
131
if ( $FileName ) {
0 commit comments