2016-05-03 7 views
-1

フォルダーに最新のファイルがあるかどうかを確認するスクリプトを作成しようとしていますが、メールを受け取っていません。フォルダ内の最新のファイルを確認する方法がわからない。どのように配置する最新のcsvをフォルダー内の電子メールに添付ファイルとして送信する方法

$outlook = New-Object -comObject Outlook.Application 
$message = $outlook.CreateItem(0) 
$message.Recipients.Add("[email protected]") #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のに新しいです)メッセージ

+1

以下のように、この作業を得ました修正する。あなたがメールを受け取っていないときにファイルを添付することには意味がありません。 – Matt

+1

あなたがそれを送るには、少なくとも '$ message.Send()'を呼び出す必要があります –

答えて

0

すべてを送って、私たちは試している問題

$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("[email protected]") #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"} 
関連する問題