GitHub Icon Image

Set Home site for SharePoint tenant

Summary

This sample script shows how to set a communication site as a home site for SharePoint online tenant.

Scenario inspired from this blog post: Set up a home site in SharePoint Online

Outupt Screenshot

  • PnP PowerShell
  • CLI for Microsoft 365 with PowerShell

# SharePoint tenant admin site collection url
$adminSiteUrl = "https://<tenant>-admin.sharepoint.com"

# Communication site collection url
$commSiteUrl = "https://<tenant>.sharepoint.com/communicationsite"

# Connect to SharePoint Online site  
Connect-PnPOnline -Url $adminSiteUrl -Interactive

# Set communication site as the home site
Set-PnPHomeSite -HomeSiteUrl $commSiteUrl

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell


# Usage example:
# .\Set-HomeSiteForSharePointTenant.ps1 -WebUrl "https://contoso.sharepoint.com/sites/Intranet"

[CmdletBinding()]
param (
    [Parameter(Mandatory = $true, HelpMessage = "Please enter Site URL, e.g. https://contoso.sharepoint.com/sites/Intranet")]
    [string]$WebUrl
    )
begin {
    #Log in to Microsoft 365
    Write-Host "Connecting to Tenant" -f Yellow

    $m365Status = m365 status
    if ($m365Status -match "Logged Out") {
        m365 login
    }

    Write-Host "Connection Successful!" -f Green 
}
process {
    # Set the specified site as the Home Site
    m365 spo homesite set --siteUrl $WebUrl
}
end { 
    Write-Host "Finished"
}

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

Contributors

Author(s)
Ganesh Sanap
Smita Nachan

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI