PowerShell is a powerful Command Line Shell Script mainly used by the administrators, and manages anything in Microsoft products. Each Microsoft product, be it Excel, SQL, Office applications, or SharePoint, has its own set of cmdlets [commands used to run any operation that can be performed using GUI and more than it].
Check the cmdlets that can be used in the SharePoint on-premises in my
previous article.
But working with SharePoint online is a bit different. The prerequisites are -
- PowerShell v3
- .NET Framework
- SharePoint Module - which can be downloaded from http://www.microsoft.com/en-us/download/details.aspx?id=35588
Once the module is downloaded, open SharePoint Online Management Shell and run the cmdlet to import the SharePoint online module cmdlets.
- Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking;
Or the SharePoint Online Management Shell can be installed directly using the link - https://www.microsoft.com/en-in/download/details.aspx?id=35588
- Connect-SPOService -Url https:
Note
The connecting site should be a tenant administrator site and the user should have tenant administrator access. The session will be active as an internal variable.
To clear out the service, run Disconnect-SPOService cmdlet which will clear the connected session.
For code reusability, it is better to create a function to connect with SharePoint Online adminstrator site.
- function ConnectSPOnlineSite() {
- param (
- $admin = "[email protected]",
- $adminSite = "https://xyz.sharepoint.com"
- )
- if ((Get-Module Microsoft.Online.SharePoint.PowerShell).Count -eq 0) {
- Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
- }
- $cred = Get-Credential $admin
- Connect-SPOService -Url $adminSite -Credential $cred
- }
There is a small change in the cmdlets of SharePoint On-premises and SharePoint Online. In "noun-verb" part of PowerShell cmdlets, the verb has prefixed Get-SPO****.
Example
Get-SPOSite- gets the site collection of particular URL/identity,
Get-SPOSiteGroup- returns all site groups of one or more site collection,
Get-SPOTenant - gets SharePoint online organization properties.
Most of the cmdlets are available till site collection level not till the site level [SPweb level as compared to SharePoint on premises ].