Tag Archives: Powershell

Powershell send-mailmessage from task scheduler

The other day I came across a curious function. I had a requirement in a script to send an email. Now, when I wrote the script and tested everything was working fine. However when I ran the script from the test schedule, the script executed fine but no email was sent!

After a few hours of searching the system of the exchange host.

Hold the phone! under my account it worked perfectly but under the service account running the task scheduler it failed.

after a few failed attempts I noticed that if I mistyped the username and password while passing the credentials to the using the -Credentials $Creds argument.. it actually work… WFT

so I quickly worked out that if I passed “dummy” credentials the script worked.

To c create a dummy credential I first had to create a secure string. Then I could pass this script type into a new credential object… as so:

in just included this at the top of the script when declaring variables.

WORKS!

 

Powershell Query Services on Remote Computer

Get Services on remote computer and save to file

Loads a list of computes and looks who is in the admin group

* get-localGroupMembers is a function:

Found Here

https://gallery.technet.microsoft.com/scriptcenter/List-local-group-members-c25dbcc4