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

[玩转系统] SharePoint Online:使用 PowerShell 设置中心网站关联

作者:精品下载站 日期:2024-12-15 00:02:08 浏览:15 分类:玩电脑

SharePoint Online:使用 PowerShell 设置中心网站关联


SharePoint Online 中的中心网站是一种新方法,可根据组织层次结构将相关网站组织到集中式门户中,以共享通用导航、品牌和搜索。有关中心网站的更多信息:如何在 SharePoint Online 中创建中心网站?,本文介绍了使用 PowerShell 将网站与中心网站关联所需的步骤。

使用 PnP PowerShell 在 SharePoint Online 中设置中心站点关联

要将网站集与现有中心网站关联,请使用以下脚本:


#Config Variables
$TenantSiteUrl = "https://crescent-admin.sharepoint.com"
$HubSiteURL = "https://crescent.sharepoint.com/sites/Intranet"
$SiteURL = "https://crescent.sharepoint.com/sites/2020projects"

#Connect to PnP Online
Connect-PnPOnline -Url $TenantSiteUrl -Credentials (Get-Credential)

#Associate Site collection with HubSite
Add-PnPHubSiteAssociation -Site $SiteURL -HubSite $HubSiteURL

让我们调整脚本位并将多个站点添加到中心站点:


#Config Variables
$TenantSiteUrl = "https://crescent-admin.sharepoint.com"
$HubSiteURL = "https://crescent.sharepoint.com/sites/Operations"
$SitesToConnect = "https://crescent.sharepoint.com/sites/Ops","https://crescent.sharepoint.com/sites/OpsV2","https://crescent.sharepoint.com/sites/OpsV3"

Try { 
    #Connect to PnP Online
    Connect-PnPOnline -Url $TenantSiteUrl -Interactive

    #Get the Hub site
    $HubSite = Get-PnPHubSite -Identity $HubSiteURL

    #Get all sites connected to the Hub
    $SitesConnectedToHub = Get-PnPHubSiteChild -Identity $HubSiteURL

    #Associate each Site collection with HubSite
    ForEach ($Site in $SitesToConnect)
    {
        #Check if the site is alreay connected with the Hub
        If($SitesConnectedToHub -contains $Site)
        {
            Write-host "$Site is Already connected to Hub Site" -ForegroundColor Yellow
        }
        Else
        {
            Add-PnPHubSiteAssociation -Site $Site -HubSite $HubSiteURL
            Write-host "$Site Connected to HUB Site Successfully!" -ForegroundColor Green
        }
    }
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

从 CSV 文件设置网站集的中心网站关联:

如果您想要将多个站点与一个中心站点关联,只需创建一个包含站点 URL 的 CSV 文件即可。这是我的:

[玩转系统] SharePoint Online:使用 PowerShell 设置中心网站关联

要将多个网站集从 CSV 文件关联到中心网站,您可以使用以下脚本:


#Config Variables
$TenantSiteUrl = "https://crescent-admin.sharepoint.com"
$HubSiteURL = "https://crescent.sharepoint.com/sites/Intranet"
$CSVFilePath = "C:\Temp\Sites.csv"

#Connect to PnP Online
Connect-PnPOnline -Url $TenantSiteUrl -Credentials (Get-Credential)

#Get data from CSV File
$Sites = Import-Csv -Path $CSVFilePath 

#Associate each Site collection with HubSite
ForEach ($Site in $Sites)
{
    Add-PnPHubSiteAssociation -Site $Site.SiteURL -HubSite $HubSiteURL
    Write-host "Associated $($Site.SiteURL) with Hub Site"! -f Green
} 

好的,如何从网站集中删除中心网站关联?那么,要从 SharePoint Online 网站集中删除中心网站关联,请使用:


Remove-PnPHubSiteAssociation -Site "<Site URL>"

要检索所有中心网站及其关联网站,请使用:使用 PowerShell 获取 SharePoint Online 中心网站关联

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

取消回复欢迎 发表评论:

关灯