question

VarugheseKochukalicalEappen-8655 avatar image
0 Votes"
VarugheseKochukalicalEappen-8655 asked MotoX80 answered

Office 365 Powershell Automated login

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered

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://docs.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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.