SharePoint Online: ตั้งค่าการเชื่อมโยงไซต์ฮับโดยใช้ PowerShell
ไซต์ฮับใน SharePoint Online เป็นวิธีใหม่ในการจัดระเบียบไซต์ที่เกี่ยวข้องเข้าด้วยกันเป็นพอร์ทัลแบบรวมศูนย์โดยยึดตามลำดับชั้นขององค์กรเพื่อแชร์การนำทาง การสร้างแบรนด์ และการค้นหาทั่วไป ข้อมูลเพิ่มเติมเกี่ยวกับไซต์ฮับ: วิธีสร้างไซต์ฮับใน SharePoint Online โพสต์นี้ครอบคลุมขั้นตอนที่จำเป็นในการเชื่อมโยงไซต์กับไซต์ฮับโดยใช้ PowerShell
ตั้งค่าการเชื่อมโยงไซต์ฮับใน SharePoint Online โดยใช้ PnP PowerShell
เมื่อต้องการเชื่อมโยงไซต์คอลเลกชันกับไซต์ฮับที่มีอยู่ ให้ใช้สคริปต์ต่อไปนี้:
#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
มาปรับแต่งบิตสคริปต์และเพิ่มหลายไซต์ลงในไซต์ Hub:
#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
}
ตั้งค่าการเชื่อมโยงไซต์ Hub สำหรับไซต์คอลเลกชันจากไฟล์ CSV:
หากคุณต้องการเชื่อมโยงหลายไซต์กับไซต์ฮับ เพียงสร้างไฟล์ CSV ด้วย URL ของไซต์ นี่คือของฉัน:
เมื่อต้องการเชื่อมโยงหลายไซต์คอลเลกชันจากไฟล์ 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>"
เมื่อต้องการดึงข้อมูลไซต์ฮับทั้งหมดและไซต์ที่เกี่ยวข้อง ให้ใช้: รับการเชื่อมโยงไซต์ฮับของ SharePoint Online โดยใช้ PowerShell
