Send-MailMessage在带有$字符的长unc文件名上失败

问题描述 投票:0回答:1

正在测试另一个正在运行的脚本,但是在处理一组新文件时遇到了麻烦。见下文。 $ Attach2导致错误,而$ Attachment1正常运行

$Attachment1 = "c:\temp\I went to the beach-and  now too.txt"
$Attach2 = '\\qa-west\e$\orders\15557__45747457-Re_[EXTERNAL]SomeBoxShipmentTestName-JoeSmithers-FileWest-232264_42211_3674745752.msg'
$smtpServer = "mail.somewhare.com"

try{
    Send-MailMessage -From '[email protected]' -To '[email protected]' -Subject 'test sub' -Body 'this is body' -SmtpServer $smtpServer -Attachments $Attachment1
}
catch {    
    # log the error
    $ErrorMessage = $PSItem.Exception.Message

    #-- test
    Write-Host $ErrorMessage

}

Send-MailMessage失败,并带有异常:

Exception:System.IO.FileNotFoundException:无法找到指定的文件。\ r \ n位于System.Management.Automation.MshCommandRuntime.ThrowTerminateError(ErrorRecorderrorRecord)

 ErrorDetails:Cannot perform operation because the wildcard path did not resolve to a file  FileName $null
powershell
1个回答
0
投票

我不认为问题在于美元,我认为这是方括号。在方括号中,方括号为wildcards,在-Attachments中,Send-MailMessage不支持通配符

在文件名的两个方括号前面添加反引号(`)。有关此问题的更多详细信息可用here

© www.soinside.com 2019 - 2024. All rights reserved.