我在下面提供了一个脚本,它使用hubsites和相关站点填充SPO列表。我在底部附近写了一行,如果SiteUrl
匹配,则应该阻止它写入更多行:
Connect-PnPOnline -Url "https://myCompany-admin.sharepoint.com" -Interactive
$Report = @()
Write-Host "Getting list of all hubsites..."
$HubSites = Get-PnPHubSite
Write-Host "Getting list of all sites excluding sites without a connected hub..."
$Sites = Get-PnPTenantSite | ? {$_.HubSiteId.Guid -ne "00000000-0000-0000-0000-000000000000"}
Write-Host "Getting the target SPO site to create items..."
$connection = Connect-PnPOnline -Url "https://myCompany.sharepoint.com/sites/HubSiteMap" -Interactive
$List = Get-PnPList "Sites" -Connection $connection
$ListItems = Get-PnPListItem -List $List
ForEach($Hub in $HubSites)
{
# Get the ID of the Hubsite
$HubSiteId = $Hub.ID.GUID
# Iterate through each site collection
ForEach($Site in $Sites)
{
# Get the Associated Hubsite ID for this site
$AssociatedHubSiteID = $Site.HubSiteId.Guid
If ( ($AssociatedHubSiteID -eq $HubSiteId) -and ($Hub.SiteUrl -ne $Site.Url) )
{
$ReportEntry = "" | Select-Object Hub,SiteUrl
$ReportEntry.Hub = $Hub.SiteUrl
$ReportEntry.SiteUrl = $Site.Url
$Report += $ReportEntry
if ($Site.Url -notin $ListItems.FieldValuesAsText.SiteUrl) { #THIS LINE IS NOT WORKING!
Add-PnPListItem -List $List -Values @{"Hub" = $Hub.SiteUrl; "SiteUrl" = $Site.Url}
}
}
}
}
字符串
SPO列表有两个单行文本列Hub
和SiteUrl
1条答案
按热度按时间k2arahey1#
像这样使用PowerShell脚本:
字符串
其中
SiteUrl
是列表中文本列的内部名称。您可以通过阅读本文获得列的确切内部名称:How to find the Internal name of columns in SharePoint Online?