kwizcom banner advertisement

How to Connect to SharePoint Online from PowerShell?

I know I said it several times, but I'll say it again: I'm a big fan of PowerShell! PowerShell makes repetitive tasks easier and makes our life smarter. It helps to automate complex tasks and reduces risk of human errors. In this article, I'm exploring how to use PowerShell with SharePoint online.

How to connect to SharePoint online using PowerShell:
Follow these steps to connect to SharePoint online via PowerShell.

Step 1: Make sure You have PowerShell and SharePoint Online PowerShell Module Installed
To download Windows Management Framework 3, which includes PowerShell 3.0:

To Download and Install SharePoint online PowerShell module:
You must download and install SharePoint Online Management Shell to start with.  Download PowerShell for SharePoint online at:
install powershell for sharepoint online

Step 2: How to Connect to SharePoint online with PowerShell
Launch "SharePoint Online Management Shell" from start menu and connect to SharePoint Online Administration Center first.
Connect-SPOService -Url `
This cmdlet must be run before we use any other SharePoint Online cmdlets. Make sure you connect with an account with the global administrator permissions and use HTTPS in the admin site URL.  You'll get The prompt for password.
Connect to SharePoint online with PowerShell

Step 3: Start using SharePoint online PowerShell cmdlets!
Once connected, you can use SharePoint Online cmdlets. Here are some examples. Lets create a site collection in SharePoint online using PowerShell.

SharePoint online PowerShell create site collection
#Lets create a new Site collection:
New-SPOSite -Url `
   -Owner -StorageQuota 1000 -Title "Sales Site" 
powershell script to connect to sharepoint online

Create group in SharePoint Online with PowerShell ISE:
You can also use PowerShell ISE. Lets create a group using PowerShell for SharePoint online.
#sharepoint online powershell create group:
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking

#Connect to SharePoint Online
Connect-SPOService -Url `

#create group
New-SPOSiteGroup -Site  `
            -Group "Sales Managers" -PermissionLevels "Full Control" 
how to run powershell on sharepoint online
Even more generic code to connect to SharePoint Online through PowerShell would be:
#Import SharePoint Online PowerShell module
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

#Admin Center URL of your SharePoint Online - Set it accordingly
$AdminSiteURL= ""

#Get credentials to connect
$Credential = Get-Credential

#Connect to SharePoint Online services
Connect-SPOService -url $AdminSiteURL -Credential $credential

Index of SharePoint online PowerShell cmdlets:
For the list of available cmdlets for SharePoint online, Refer: SharePoint online 2013 PowerShell cmdlets at
You can also use this cmdlet to list SharePoint online PowerShell cmdlets:
Get-Command –Module Microsoft.Online.SharePoint.PowerShell
connect to sharepoint online using powershell

Limitation: Unlike SharePoint on-premises, SharePoint online offers only least set of PowerShell cmdlets to manage SharePoint online. E.g. There is no direct PowerShell cmdlets to activate feature, create subsite, create list, add list item, etc. Solution would be utilizing client side object model (CSOM) with PowerShell!
Client Side Object Model (CSOM) is a subset of: SharePoint Online Management Shell!

Tags: powershell script to connect to sharepoint online, how to connect to sharepoint online using powershell, how to run powershell script for sharepoint online, how to use powershell with sharepoint online, manage sharepoint online with powershell, install sharepoint online powershell module
How to Connect to SharePoint Online from PowerShell? How to Connect to SharePoint Online from PowerShell? Reviewed by Salaudeen Rajack on January 27, 2015 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.