Office 365 Powershell Automated login

Varughese Kochukalical Eappen 21 Reputation points
2021-07-24T09:22:41.217+00:00

I have an On Premises server in which I have 2 Office 365 powershells opened.
One for MSOnline powershell to automatedly assign license and enable MFA for new users
Another Exchange online powershell for certain exchange related automated tasks.

Problem is the server is set to restart once a month for patch updates and each time I have to launch these powershells manually to enter the credentials.
Is there any way to launch the powershells automatedly without me having to enter credentials manually.

Note: Azure Automation cannnot be considered.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2021-07-24T13:01:12.687+00:00

    Just use the Windows task scheduler to run them at system startup. Set the task to run as an account that has the required access. If the scripts require a different account then you can set a credential object.

    https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/add-credentials-to-powershell-functions?view=powershell-5.1

    https://o365info.com/connect-office-365-using-powershell-script-using-saved-encrypted-user-credentials

    The processes will be "running in the background" so when you log on to the server you won't see the console window. You'll need to have the script write activity to a log file that you can then look at to see what they are doing.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.