Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在文件夹中以电子邮件附件的形式发送最新的csv_Csv_Powershell_Attachment - Fatal编程技术网

如何在文件夹中以电子邮件附件的形式发送最新的csv

如何在文件夹中以电子邮件附件的形式发送最新的csv,csv,powershell,attachment,Csv,Powershell,Attachment,我试图写一个脚本,在文件夹中寻找最新的文件,并通过电子邮件发送给用户,在运行下面的脚本后,我没有收到任何错误,但我没有收到任何电子邮件。不确定如何检查文件夹中的最新文件 $outlook = New-Object -comObject Outlook.Application $message = $outlook.CreateItem(0) $message.Recipients.Add("test@test.com") #obviously this is not the right

我试图写一个脚本,在文件夹中寻找最新的文件,并通过电子邮件发送给用户,在运行下面的脚本后,我没有收到任何错误,但我没有收到任何电子邮件。不确定如何检查文件夹中的最新文件

$outlook = New-Object -comObject Outlook.Application 
$message = $outlook.CreateItem(0)
$message.Recipients.Add("test@test.com")  #obviously this is not the right   email
$message.Subject = "test"  
$message.Body = "this is test email"


$file = "P:\test\test.csv"
$message.Attachments.Add($file)
嗨,我已经尝试在互联网上搜索,并把一个脚本,以列出最新的文件现在我只需要附加文件,并通过电子邮件发送

$dir = "P:\Source\"
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending   
| Select-Object -First 1
$newfile = $latest.name



$FilePath = Join-Path $dir $newfile
$FileExists =  test-path $FilePath 

If ($FileExists -eq $True)

{email bit should come here}

不确定如何放置发送消息(我是powershell的新手)

我得到的结果如下

$dir = "p:\test\"
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending 
| Select-Object -First 1
$newfile = $latest.name



$FilePath = Join-Path $dir $newfile
$FileExists =  test-path $FilePath 

If ($FileExists -eq $True) {
$outlook = New-Object -comObject Outlook.Application 
$message = $outlook.CreateItem(0)
$message.Recipients.Add("test@test.com")  #obviously this is not the right    
email
$message.Subject = "test"  
$message.Body = "this is test email"


$file = $FilePath
$message.Attachments.Add($file)
$message.Send()
Write-Host "File is emailed "
}
else
{write-host "No File Found"}

我们应该尝试解决哪些问题。当您没有收到邮件时,处理附加文件没有意义。如果要发送邮件,您至少需要调用
$message.Send()