Forum Discussion

dmarquesgn's avatar
dmarquesgn
Iron Contributor
Aug 18, 2022
Solved

Running a powershell "MessageTrace" command within a scheduled task

Hi,

 

I need to run a powershell script 4 times a day, to return the number of emails sent from a specific mailbox. I've got my code running fine and returing an email with the count of sent emails until the actual time.

Now I need to run my powershell code from a scheduled task, so I can run it everyday. The problem is that I'm using this command to connect to Exchange Online: 
Connect-ExchangeOnline -UserPrincipalName email address removed for privacy reasons

So, running from a schedule task, I'm not there to authenticate, so the script will not be succedeed. Of course I'm not going to insert my credentials on the powershell script.

So I can I authenticate to Exchange Online when running the powershell from a schedule task?

 

Thanks

7 Replies

Resources