Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

powershell script not sending email when run as a scheduled task

$
0
0

Hi All,

I was given some help from you guys to get a wmi reboot check working which it now does fine but when i run it as a task I do not get the email.

This is what I run on a w2008r2 box

$a = gc c:\Servers.txt | %{
$lastBoot = Get-WmiObject Win32_OperatingSystem -computer $_ | %{[System.Management.ManagementDateTimeCOnverter]::ToDateTime($_.LastBootUpTime)}
$obj = New-Object –TypeName PSObject –Prop(@{'LastBoot'=$lastBoot;'Name'=$_;})
$obj

Send-MailMessage -From "a.user@abc.com" -To "b.user@abc.com" -Subject "XA Reboot Check" -Body  ($a | out-string) -smtp smtpserver

And for the scheduled task I run it at the highest privilege and tell it to start a program Powershell -File C:\Temp\Scripts\RebootCheck.ps1

Any idea on what I am doing wrong would be great

 


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>