Quick Powershell script for connecting to SharePoint Online/ Office 365

At work, we’ve started working with Sharepoint online/ O365, and it’s a bit tedious to type in the whole connection command each time.

I wanted a simple script that would store the name of our tenant, my username, and would then securely prompt me for my password:

#Admin Variables:
$Adminurl = "https://tenantname-admin.sharepoint.com"
$username = "youremail@youremail.com"

#Connect to SPO
$SecurePWD = read-host -assecurestring "Enter Password for $username"
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $SecurePWD
write-host "Connecting"
Connect-SPOService -url $Adminurl -credential $credential
write-host "Connected" -foregroundcolor green


Leave a Reply