当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 获取网站标题

作者:精品下载站 日期:2024-12-14 21:16:55 浏览:12 分类:玩电脑

SharePoint Online:使用 PowerShell 获取网站标题


要求:使用 PowerShell 获取 SharePoint Online 网站标题。

如何获取 SharePoint Online 中的网站名称?

您可能需要在从 SharePoint Online 网站生成的报告中快速引用网站的标题。在这篇博文中,我将向您展示如何使用 PowerShell 获取 SharePoint Online 网站的标题。

要获取站点名称或站点标题,只需登录该站点>>单击“设置齿轮”>>选择“站点信息”>>您就会找到站点标题!

[玩转系统] SharePoint Online:使用 PowerShell 获取网站标题

SharePoint Online:使用 PowerShell 获取网站标题

让我们使用 PowerShell 脚本获取 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 获取网站集标题

我们还可以在站点级别使用此 CSOM PowerShell 脚本来获取站点名称。


#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
}

使用 PnP PowerShell 检索 SharePoint Online 网站标题

如果您正在寻找一种使用 PnP PowerShell 在 SharePoint Online 中获取网站标题的方法,请执行以下操作:


#Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"

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

#Get the Root Web
$Web = Get-PnPWeb

#Get the Site Title
Write-host -f Green $Web.Title

总之,使用 PowerShell 检索 SharePoint Online 中的网站名称是一项简单的任务,只需几行脚本即可完成。通过使用 PowerShell,SharePoint 管理员可以自动执行许多任务,包括检索网站信息。本文提供的脚本是如何检索站点名称的简单示例,可以对其进行修改以满足其他需求。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯