This article will show you how to connect to Office 365 automatically using a PowerShell script.
This can be Integrated In a scheduled task script that connect to Office 365 to perform a back office task which I personally do or as a starter script to connect to Office 365.
You can also use this to connect script to connect to Office 365 without typing a username and password.
Don’t forget to visit my article on how to Connect And Manage Office 365 Using PowerShell to get PowerShell configured correctly for Office 365.
Code:
$powerUser = "name@name.onmicrosoft.com" $powerPass = "Password" $password = ConvertTo-SecureString $powerPass -AsPlainText -Force $adminCredential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $powerUser,$password $O365Cred = $adminCredential Connect-MsolService –Credential $O365Cred