SharePoint Online: Get Site Title using PowerShell

Requirement: Get SharePoint Online site title using PowerShell

SharePoint Online: Get Site Title using PowerShell
Let's use PowerShell CSOM script to get site title in SharePoint Online.
#Parameters
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"

#Connect to SharePoint Online
Connect-SPOService -Url $AdminSiteURL -Credential (Get-Credential)

#Get the Site Collection
$Site = Get-SPOSite -Identity $SiteURL

#Get Site Collection Title
Write-host $Site.Title

PowerShell to Get Site Collection Title 
We can also use this PowerShell script at tenant level to get site title.
#Import PoweShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

#Parameter
$SiteUrl = "https://crescent.sharepoint.com/sites/marketing"

#Get Credentials to connect
$Cred = Get-Credential

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get the web
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.ExecuteQuery()

    #Get the site title
    Write-host -f Green "Site Title:" $Web.Title
}
catch {
    write-host "Error Getting Site Title: $($_.Exception.Message)" -foregroundcolor Red
}

Retrieve SharePoint Online Site Title using PnP Powershell
#Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin #-Credential (Get-Credential)

#Get the Root Web
$Web = Get-PnPWeb

#Get the Site Title
Write-host -f Green $Web.Title
SharePoint Online: Get Site Title using PowerShell SharePoint Online: Get Site Title using PowerShell Reviewed by Salaudeen Rajack on March 04, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.