SharePoint Online Common Shell Commands

Sharing a few SharePoint online common shell commands that can be used by SharePoint administrators for day to day operations.

First Download the Sharepoint Online Management Shell from below link

https://www.microsoft.com/en-us/download/details.aspx?id=35588

ones above is done connect to the online Shell –>Connect-SPOService -Url https://orgName-admin.sharepoint.com

To get ALL Sharepoint Online sites use below:

Get-SPOSite -Limit ALL

To exclude the office 365 groups from the above results use below command

Get-SPOSite -Filter { Template -ne “Group#0” }

To include all Personal or One-drive sites in the result use the command:

Get-SPOSite -IncludePersonalSite $true

You can add a where clause to include only personal sites:

Get-SPOSite -IncludePersonalSite $true | where{$_.url -like “*/personal/*”}

ADD Site collection administrator to existing site collection.(you can use this in case you want to add extra admin to one-drive for accessing files of terminated employee)

Set-SPOUser -site “http://SiteCollURL” -LoginName “VikasSukhija@Syscloudpro.com” -IsSiteCollectionAdmin $True

You can use GUI to add additional Site collection administrator from admin console as well but that is limited to Site collections that are created from there.

 

 

To get delete sites so that you can know the exact url that you want to restore.

Get-SPODeletedSite

Use Get-SPODeletedSite -IncludePersonalSite to include deleted one-drive sites.

To restore the deleted sites use Restore-SPODeletedSite -Identity https://SiteUrl

Disconnect from SharePoint Online management Shell using : Disconnect-SPOService

Only limited set of commands  are available in Sharepoint online  in comparison with Sharepoint onpremise but Sharepoint Client object model can be utilized to do many administration tasks.

For example: To fetch creation date and time of a site, get-sposite will not fetch it but client object model can do that easily.

First load the client DLLS

Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”

Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”

Now authenticate to SharePoint online

$userid = “vikass@labtest.com”

$pwd = Read-Host -Prompt “Password” –AsSecureString

$siteurl = “http://labtest.sharepoint.com/sites.test”

$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$ctx.credentials = $creds

Load & execute the query now:

$web = $ctx.web

$ctx.Load($web)

$ctx.ExecuteQuery()

Now to check the creation date/time of the site just type:

$web.created

—————————————————————————————————————————————————————————-

Thanks for Reading

Sukhija Vikas

http://SysClousPro.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s