Hi @Roger Roger
Thank you for reaching out to Microsoft Learn Q&A!
Based on your description, I understand you're looking to confirm whether the account used in Task Scheduler is the same one being referenced in your Exchange Remote PowerShell script.
As a forum moderator, I don’t have access to a dedicated testing environment to replicate specific user scenarios. However, driven by our mission to support the community, I’ve conducted some research and I’m happy to share insights that I hope will be helpful.
According to the following Microsoft Learn article, your script1.ps1 should run successfully as a standalone script in an interactive session: Connect to Exchange servers using remote PowerShell | Microsoft Learn
However, when used in combination with Task Scheduler, the Get-Credential step may not be optimal for automation. From my research, if you do not explicitly specify a user in the -Credential parameter, PowerShell defaults to the current user. This typically aligns with the account configured in Task Scheduler, assuming it has the necessary permissions.
You might consider using a static credential input instead of prompting for credentials dynamically. Please note that while this method can be useful for testing, it’s not recommended for production use due to privacy and security concerns, as credentials may be exposed.
I sincerely hope this information partially clarifies your situation and assists you in planning your solution. Please know that while our initial response might not resolve the issue right away, your input is incredibly valuable. With a bit more detail, we’ll work together to find the best solution for you.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread