【发布时间】:2020-05-15 00:04:30
【问题描述】:
我在使用 PowerShell Send-MailMessage 命令时收到以下错误。
Send-MailMessage : Could not find file 'C:\ABC_$getDateTime.xls'
代码:
$getDateTime = ((get-date).ToString("yyyyMMddHHmm"))
C:\tsizepro.exe /EXCEL "C:\ABC_$getDateTime.xls" /NOGUI "\\path\path"
Send-MailMessage -From 'xyzy@xyz.com' -To 'xyz@xyz.com' -Subject "Test email for $getDateTime" -Body "Please find the attached report for $getDateTime" -Attachments "C:\ABC_$getDateTime.xls" -SmtpServer 'smtpservername'
当我从错误中复制路径并在资源管理器中打开它时,它会毫无问题地打开。我也尝试过以管理员身份运行 PowerShell,但仍然出现同样的错误。
PowerShell 版本是 4.0。
请不要担心 tsizepro.exe。它只是一个提取存储报告并将其导出到 Excel 中的工具。
【问题讨论】:
-
会不会是文件名被 tsizepro.exe 工具修改了?还是让它继续使用?也许颠倒行的顺序,所以先发送 Excel,然后让工具对其进行处理?