-1
Powershell을 처음 사용하며 현재 첨부 파일이 포함 된 전자 메일을 보내는 방법을 찾고 있습니다. 내가 다음과 같은 스크립트에서 작동하려고했지만 오류 메시지 (스크립트의 끝에 나열)를주는 날에 실패, 내가 뭘 잘못하고 어떻게 고칠 지 제안하십시오.첨부 파일이있는 powershell에서 Powershell을 사용하여 전자 메일 보내기
-----------Start -----------
$SourceDir = "D:\powershell testing\*.csv"
$files= Get-ChildItem "$SourceDir"
# ---------------
if (Test-Path $SourceDir)
{ if ((Get-Item $file).length -gt 5kb)
{
Start-Process outlook
$o = New-Object -com Outlook.Application
Foreach($file in $files)
{
# -----Email attributes-----
$mail = $o.CreateItem(0)
$mail.importance = 2
$mail.subject = "Problem with LDAP Feed"
$mail.body = "Please be advised that there is a problem identified with LDAP feed and it is suggested to visit the Automation box for further diagnosis"
$mail.To = "[email protected]"
# ----Attachments -------
Write-Host "Attaching File :- " $file
$attachment = new-object Net.Mail.Attachment.Add($file)
$msg.Attachments.Add($attachment)
}
# $o.Quit()
}
}
-----------End--------------
Error Message :
==============
Get-Item : Cannot find path 'C:\Windows\system32\error 1.csv' because it does not exist.
At line:7 char:19
+if ((Get-Item <<<< $file).length -gt 5kb)
+ CategoryInfo: ObjectNotFound:(C:\Windows\system32\error 1.csv:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId: PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand