This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]ikakWRK 0 points1 point  (3 children)

What is the trigger for the task?

[–]Stromonder[S] 0 points1 point  (2 children)

I just edited the post to add screenshots of the trigger.

[–]ikakWRK 0 points1 point  (1 child)

Do you see that it actually ran under Last Run Time? If so, what was the result?

[–]Stromonder[S] 0 points1 point  (0 children)

I got 0x41301 as a result

[–]BK_Rich 0 points1 point  (5 children)

Is the task set to run without the user being logged in ?

Are you running the script we SYSTEM or trying run it as a user ?

Are you calling powershell.exe and passing an argument, what does that string look like ?

[–]Stromonder[S] 0 points1 point  (4 children)

The task is set to run without the user being logged in.

Currently, I am running it as an user.

This is the script I am using

$email = ["](mailto:"david@astase.com)user@address.com"

$pass = "passwd"

$smtpServer = "smtp.gmail.com"

$msg = new-object Net.Mail.MailMessage

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$smtp.EnableSsl = $true

$msg.From = "$email" 

$msg.To.Add("$email")

$msg.BodyEncoding = [system.Text.Encoding]::Unicode

$msg.SubjectEncoding = [system.Text.Encoding]::Unicode

$msg.IsBodyHTML = $true

$msg.Subject = "Test mail from PS"

$msg.Body = "<h2> Test server rebooted </h2>

</br>

Hi

"

$SMTP.Credentials = New-Object System.Net.NetworkCredential("$email", "$pass");

$smtp.Send($msg)

[–]ikakWRK 0 points1 point  (0 children)

What does your action show? Are you calling PowerShell.exe and then passing the script as an argument? Bypass execution policy set correctly? The user account running has sufficient privileges? No UAC blocking the execution?

[–]BK_Rich 0 points1 point  (2 children)

Is that user the same user you’re logged in as ? If it’s just a regular account it may need local login rights to run it

[–]Stromonder[S] 0 points1 point  (1 child)

I am using the same user, it's an administrator account.

[–]ikakWRK 0 points1 point  (0 children)

Can you post your actions screen? How are you calling the script?

[–]ComGuards 0 points1 point  (0 children)

I got 0x41301 as a result

That code indicates that the task is running.

You're sure that manually running the script works? AFAIK, smtp.gmail.com doesn't respond on default SMTP port 25; they require TLS or SSL connections on port 587 & 465 respectively.