I read a ton of articles on this and a bunch of posts here, tried all the suggestions and not having any luck.

I’m using a script that sends emails to people who’s passwords are about to expire from here: Link

I self-signed it so I don’t need to bypass the execution policy.

I have powershell.exe as the target. (I had the full path before also)

As arguments I have: C:\scripts\PwdChangeNotification.ps1 -smtpServer -ca.mail.protection.outlook.com -expireInDays 10 -from "IT Support <@.ca>" -Logging -LogPath c:\logFiles -reportTo "@*.ca"

(*'s is just to hide personal info)

When I paste that line as-is into powershell it executes with no issue.

when I run it from task scheduler I get: “powershell.exe” with return code 2147942401. (aka F** you from Microsoft-have a pleasant day)

I tried:

-Command &" ‘C:\scripts\PwdChangeNotification.ps1’ -smtpServer -ca.mail.protection.outlook.com -expireInDays 10 -from "IT Support <@.ca>" -Logging -LogPath c:\logFiles -reportTo "@*.ca" "

I also tried the -File option but had no luck either.

I’m starting to think it will be easier to put it in a batch file and then run that via task scheduler at this point. Why is something so easy so hard to get working?!

2 Spice ups

If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton_small.png

why don’t you put all that stuff in the script, that would make it much easier.

https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler

like this if you move all the paramaters in the script

Program: powershell
Argument" -executionpolicy bypasspass " C:\scripts\PwdChangeNotification.ps1 "

That would be awesome but I downloaded a pre-made script and its all set up for receiving a bunch of things. I’ll try and figure out how to define them in the script instead.

Just make it a function and call it in the script, and then schedule it as I showed you above

script.txt (13.3 KB)

2 Spice ups

Ahh Sorry I did not realize that’s even a thing, I’m very new with powershell but that makes total sense!

Tested and works perfectly now :D!!

Thanks so much!

1 Spice up