我正在为我的入门CyberSec类进行一个项目(加分),并且我有一个cmd脚本来在USB驱动器中创建一个包含信息的文件,我试图使用Powershell向自己发送电子邮件,但始终收到此错误:
At D:\mail.ps1:6 char:16
+ $att= $USBDRIVE\file.zip
+ ~~~~~~~~~
Unexpected token '\file.zip' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
这是我整个的powershell脚本。
$USBDRIVE= Get-WMIObject Win32_Volume | ? { $_.label -eq 'ARNOLDHMW' } |
select -expand driveletter
Compress-Archive -Path $USBDRIVE\file -DestinationPath $USBDRIVE\file.zip
$email = "*"
$pass = "*"
$att= $USBDRIVE\file.zip
$smtpServer = "smtp.gmail.com"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.EnableSSl = $true
$msg.From = "$email"
$msg.To.Add("$email")
$msg.IsBodyHTML = $true
$msg.Subject = "Files Captured"
$msg.Body = "
</br>
Hi there
"
$msg.Attachments.Add($att)
$SMTP.Credentials = New-Object System.Net.NetworkCredential("$email",
"$pass");
$smtp.Send($msg)
电子邮件和密码因明显原因而被清空,我在这里茫然不知所措。我在这里先向您的帮助表示感谢!
我很确定您遇到的问题是因为传递给分配的$att
值不是字符串值。尝试将变量分配为字符串
$att = "$USBDrive\File.zip"
或更好
$att = Join-Path -Path $USBDrive -ChildPath "file.zip"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句