Useful Office 365 Cmdlets To Generate SharePoint Online Reports And Site Administration

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. 

utilizing

So, let’s get into the real meat and potatoes. 
  1. 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,

    new

    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:

    center
  2. To list the groups and all the group memberships for all of your SharePoint Online sites.

    Syntax:
    1. $x = Get - SPOSite  
    2. foreach($y in $x)   
    3. {  
    4.     Write - Host $y.Url - ForegroundColor "Yellow"  
    5.     $z = Get - SPOSiteGroup - Site $y.Url  
    6.     foreach($a in $z)   
    7.     {  
    8.         $b = Get - SPOSiteGroup - Site $y.Url - Group $a.Title  
    9.         Write - Host $b.Title - ForegroundColor "Cyan"  
    10.         $b | Select - Object - ExpandProperty Users  
    11.         Write - Host  
    12.     }  
    Running the above mentioned command will display the results, as shown below,

    display

  3. 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.
    1. $siteURL = "https://vigx.sharepoint.com/teams/test"  
    2. $x = Get - SPOSiteGroup - Site $siteURL  
    3. foreach($y in $x)  
    4. {  
    5.     Write - Host $y.Title - ForegroundColor "Yellow"  
    6.     Get - SPOSiteGroup - Site $siteURL - Group $y.Title | Select - Object - ExpandProperty Users  
    7.     Write - Host  
    8. }  
    Running this command will display the results, as shown below.

    command

  4. 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.

    command

    Running this command will lock the site and when you try to access it you will get a 403 Forbidden error.

  5. To unlock the SharePoint Online site.

    Syntax:

    Set-SPOSite -Identity $site -Lockstate Unlock.

    command

    This will unlock the site that we just locked in the previous command.

  6. 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

    command

    You can verify this in your SharePoint Online admin center. The site in question will have external sharing disabled, as shown below.
    sharing

  7. To enable external user and guest sharing.

    Syntax: 

    Set-SPOSite -Identity $siteURL -SharingCapability ExternalUserandGuestSharing.

    code

    Running this command will enable external user and guest sharing in a SPO site collection and you can verify that in the screenshot below.
    sharing

    Note: By default, this feature will be disabled for SPO sites and this has to be enabled if required.

  8. To enable only external user sharing:

    Syntax:

    Set-SPOSite -Identity $siteURL -SharingCapability ExternalUserSharingOnly

    Syntax

    Running this command will only enable external user sharing in an SPO site collection and you can verify that in the screenshot below.
    sharing

  9. To get the list of sites where sharing capability has been enabled.

    Syntax:

    Get-SPOSite | Where {$_.SharingCapability -ne "Disabled"}

    Syntax

  10. To get the list of sites where sharing capability is disabled:

    Syntax:

    Get-SPOSite | Where {$_. SharingCapability -eq "Disabled"}

    Syntax

  11. 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]

    Syntax

  12. To change the storage and resource quota of a site:

    Syntax

    Set-SPOSite -Identity $siteURL -StorgaeQuota 1000 -ResourceQuota 500.

  13. To change the Title of the site:

    Syntax

    Set-SPOSite $siteURL -Title “New Title”,

    Syntax

This will change the title of the site in question. You can verify this below.

title

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.

Up Next
    Ebook Download
    View all
    Learn
    View all