send-mailmessage打开文件而不是发送它

时间:2014-01-08 16:19:44

标签: powershell-v2.0

有谁可以告诉我为什么打开而不是发送文件?

$d = [DateTime]::Today.AddDays(-90)
Get-ADComputer -Filter 'lastLogon -le $d' -Properties lastLogon | 
Export-Csv c:\temp\stale_servers.csv    
If (c:\temp\stale_servers.csv = $?) 
{
 Send-MailMessage -SmtpServer xxxxxxxxx -To xxxxxxxxx -From xxxxxx -Subject "test mail" -Body "The servers that have not logged in, in the past 90 days are attached." -attachment c:\temp\stale_servers.csv
}

1 个答案:

答案 0 :(得分:1)

我认为问题出在这一行:

If (c:\temp\stale_servers.csv = $?) 

如果你想测试文件的存在使用:

If (test-path -path "c:\temp\stale_servers.csv" )