Once installed you can open the SharePoint Online Management Shell, it is implemented as a PowerShell module which also allows you to use it in another PowerShell editor by manually loading the required module Import-Module Microsoft.Online.SharePoint.PowerShell.
To establish a connection to your SharePoint Online tenant you will need to use the Connect-SPOService cmdlet (Remember that you must use the tenant admin site url as a parameter). This will fill up a static internal variable which will be used afterwards. You should clear this internal variable using the Disconnect-SPOService cmdlet.
Connect-SPOService –Url https://yoursite-admin.sharepoint.com –credential firstname.lastname@example.org
Once you are connected you can manipulate your SharePoint Online environment. There are only 30 cmdlets available in for SharePoint Online – to get a full list type the following command.
Get-Command –Module Microsoft.Online.SharePoint.PowerShell
All cmdlets start with SPO. Most cmdlets are related to site collection management, user and app management. All returned object are simple data objects and most of them are limited in functionality.
Adds an existing Office 365 user or an Office 365 security group to a SharePoint group.
Connects a SharePoint Online global administrator to a SharePoint Online connection (the SharePoint Online Administration Center). This cmdlet must be run before any other SharePoint Online cmdlets can run.
Disconnects from a SharePoint Online service.
Returns application errors.
Returns all installed applications.
Returns all deleted site collections that are in the Recycle Bin.
Returns one or more site collections.
Returns all the groups on the specified site collection.
Retrieves SharePoint Online company logs.
Returns the time when the SharePoint Online organization logs are collected.
Returns the SharePoint Online user or security group accounts that match given search criteria.
Shows all site templates that match the given identity.
Creates a new SharePoint Online site collection for the current company.
Creates a new group in a SharePoint Online site collection.
Removes a SharePoint Online deleted site collection from the Recycle Bin.
Sends a SharePoint Online site collection to the SharePoint Online Recycle Bin.
Removes a SharePoint Online group from a site collection.
Removes a user or a security group from a site collection or a group.
Checks and repairs the specified site collection and its contents.
Requests to create a copy of an existing site collection for the purposes of validating the effects of upgrade without affecting the original site.
Restores a SharePoint Online deleted site collection from the Recycle Bin.
Sets or updates the values of one or more properties for a site collection.
Updates the SharePoint Online owner and permission level on a group inside a site collection.
Sets properties on the SharePoint Online organization.
Configures properties on an existing user.
Tests a SharePoint Online site collection.
Starts the upgrade process on a site collection.
There are no cmdlets available for managing SharePoint objects at a lower scope than the site collection. The following examples show you some examples of the more common cmdlets. To see a list of site collections associated with a subscription or to see the details for a specific site collection use the Get-SPOSite cmdlet. Use the following command to retrieve the details about a specific SharePoint Online site collection. You need to specify the –Detailed option to retrieve information about CompatibilityLevel,ResourceUsageCurrent,ResourceUsageAverage, StorageUsageCurrent,Webcount and the Title.
Get-SPOSite https://yoursite.sharepoint.com –Detailed | select *
A slight variation on the script above allows you to get usage data about all of your different SharePoint Online site collections. The use of –limit all allows you to get all of the SP Online site collection, standard it will only return 200.
Get-SPOSite –limit all –detailed | Export-CSV –path MyReport.csv
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI.
The next sample code shows how you can use these assemblies from Powershell which allow you to do a lot more with PowerShell and SharePoint Online.
$loc = "C:\Powershell" # Location of DLL's
$siteUrl = "https://yoursite.sharepoint.com"
$loginname = "email@example.com"
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
Write-Host "Please enter password for $($siteUrl):"
$pwd = Read-Host -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
# Authenticate against SharePoint Online
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($loginname, $pwd)
$web = $ctx.Web
Write-Host " Current web title is '