0
1
We're having issues when using the Invoke-Command command in Powershell to manually trigger a remote Scheduled Task on another system.
Here's the situation: A server XXX has a scheduled task, that runs a Powershell script. Inside that script, at some point, it triggers this line of code: Invoke-Command -Computer "SLMTL-WSUS01.XXX.inc" -ScriptBlock {schtasks /run /tn "Windows Update - Email Reporting"}
. The invoked scheduled task simply calls another Powershell script that gets content from an HTML file, and sends it by email.
The issue lies here: When the scheduled task is called via the Invoke-Command
command, the task's Powershell script runs, but no email is sent.
If I run the task manually, it works fine and the email is sent.
Both scheduled tasks are running as SYSTEM, if that matters.
The reason we're doing it remotely like that is because we don't want to allow multiple servers to send email internally, and want to restrict it to a single one.
Does someone know why that's happening ?
Thanks in advance!
EDIT: Here's the properly-formatted script:
$Content = Get-Content "\\slmtl-wsus01.XXX.inc\Update_Reports\*.html"
$messageParameters = @{
Subject = "Windows Update report - $((Get-Date).ToShortDateString())"
Body = $Content | Out-String
from = "wsusalerts@XXX.com"
To = "apilon@XXX.com"
SmtpServer = "smtp.XXX.com"
}
Send-MailMessage @messageParameters -BodyAsHtml
As for the configuration of the task:
Action: Start a program > C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -file "\\slmtl-wsus01.XXX.inc\Scripts\WSUS_SendReportEmail.ps1"
User account used: SYSTEM, with "Run whether user is logged on or not" and "Run with Highest privileges" enabled.Everything else is the default configuration of a scheduled task, no modification. – Alex Pilon – 2017-06-02T20:43:22.210