Follow my previous article about useful Office 365 cmdlets in SharePoint Online.
In this article, I’ll be showing you some more useful PowerShell cmdlets to generate SharePoint Online reports /SharePoint Online site administration. I see a lot of misconceptions among my fellow SharePoint workers on understanding the difference between SharePoint On-Premises cmdlets and Office 365 (SharePoint Online) cmdlets. Please note that they don’t have the same functionality even though they almost look similar. There is a lot of difference in what they exactly do. So, please pay close attention while utilizing them.
So, let’s get into the real meat and potatoes.
- To create a new SPO Site collection:
Syntax:
New-SPOSite -Url https://vigx.sharepoint.com/sites/Vignesh -Title "Vignesh" -Owner "[email protected]" -Template "STS#0" -TimeZoneId 10 -StorageQuota 200,
In the above mentioned command, you need to specify the URL of your new site collection, Title Name, Template ID, Time Zone, and Storage quota size. Please check my previous article on SharePoint Online command to get to know about SharePoint Online Template IDs.
Running this command will create a new site collection in SPO and you can verify this in your SPO admin center, as shown below:
- To list the groups and all the group memberships for all of your SharePoint Online sites.
Syntax:
- $x = Get - SPOSite
- foreach($y in $x)
- {
- Write - Host $y.Url - ForegroundColor "Yellow"
- $z = Get - SPOSiteGroup - Site $y.Url
- foreach($a in $z)
- {
- $b = Get - SPOSiteGroup - Site $y.Url - Group $a.Title
- Write - Host $b.Title - ForegroundColor "Cyan"
- $b | Select - Object - ExpandProperty Users
- Write - Host
- }
- }
Running the above mentioned command will display the results, as shown below,
- To list the groups and all the group memberships for a single site collection.
Syntax:
First, let me assign the $siteURL variable to the site collection in question.
$siteURL = “https://vigx.sharepoint.com/teams/test”--> Site in question.
- $siteURL = "https://vigx.sharepoint.com/teams/test"
- $x = Get - SPOSiteGroup - Site $siteURL
- foreach($y in $x)
- {
- Write - Host $y.Title - ForegroundColor "Yellow"
- Get - SPOSiteGroup - Site $siteURL - Group $y.Title | Select - Object - ExpandProperty Users
- Write - Host
- }
Running this command will display the results, as shown below.
- To lock a SharePoint Online site.
Syntax:
Set-SPOSite -Identity $site -Lockstate NoAccess
Specify the $site variable to the site which you want to lock.
Running this command will lock the site and when you try to access it you will get a 403 Forbidden error.
- To unlock the SharePoint Online site.
Syntax:
Set-SPOSite -Identity $site -Lockstate Unlock.
This will unlock the site that we just locked in the previous command.
- To disable external sharing for a SharePoint Online site collection:
Syntax:
$siteURL = “https://vigx.sharepoint.com/teams/test”--> Site in question
Set-SPOSite -Identity $siteURL -SharingCapability Disabled
You can verify this in your SharePoint Online admin center. The site in question will have external sharing disabled, as shown below.
- To enable external user and guest sharing.
Syntax:
Set-SPOSite -Identity $siteURL -SharingCapability ExternalUserandGuestSharing.
Running this command will enable external user and guest sharing in a SPO site collection and you can verify that in the screenshot below.
Note: By default, this feature will be disabled for SPO sites and this has to be enabled if required.
- To enable only external user sharing:
Syntax:
Set-SPOSite -Identity $siteURL -SharingCapability ExternalUserSharingOnly
Running this command will only enable external user sharing in an SPO site collection and you can verify that in the screenshot below.
- To get the list of sites where sharing capability has been enabled.
Syntax:
Get-SPOSite | Where {$_.SharingCapability -ne "Disabled"}
- To get the list of sites where sharing capability is disabled:
Syntax:
Get-SPOSite | Where {$_. SharingCapability -eq "Disabled"}
- To change the owner of site.
Syntax:
First, let me assign the $siteURL variable to the site collection in question.
$siteURL = “https://vigx.sharepoint.com/teams/test”--> Site in question
Set-SPOSite -Identity $siteURL -Owner “[email protected]”
- To change the storage and resource quota of a site:
Syntax:
Set-SPOSite -Identity $siteURL -StorgaeQuota 1000 -ResourceQuota 500.
- To change the Title of the site:
Syntax:
Set-SPOSite $siteURL -Title “New Title”,
This will change the title of the site in question. You can verify this below.
Thanks for reading this article. This is all I have for this post. I’ll be back with Part Three of this article very soon.