Skip to content

Commit bf12c5c

Browse files
authored
Merge pull request #132 from natescherer/addservicenowattachment-powershell7
Fix #131 (Add-ServiceNowAttachment not working on PowerShell 7)
2 parents 19d30bb + 44e8b71 commit bf12c5c

File tree

2 files changed

+641
-2
lines changed

2 files changed

+641
-2
lines changed

ServiceNow/Public/Add-ServiceNowAttachment.ps1

+6-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ Function Add-ServiceNowAttachment {
114114
ForEach ($Object in $File) {
115115
$FileData = Get-ChildItem $Object -ErrorAction Stop
116116
If (-not $ContentType) {
117-
Add-Type -AssemblyName 'System.Web'
118-
$ContentType = [System.Web.MimeMapping]::GetMimeMapping($FileData.FullName)
117+
# Thanks to https://github.com/samuelneff/MimeTypeMap/blob/master/MimeTypeMap.cs from which
118+
# MimeTypeMap.json was adapted
119+
$ContentTypeHash = ConvertFrom-Json (Get-Content "$PSScriptRoot\..\config\MimeTypeMap.json" -Raw)
120+
121+
$Extension = [IO.Path]::GetExtension($FileData.FullName)
122+
$ContentType = $ContentTypeHash.$Extension
119123
}
120124

121125
# POST: https://instance.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=d71f7935c0a8016700802b64c67c11c6&file_name=Issue_screenshot

0 commit comments

Comments
 (0)