问题描述
尝试使用SharePoint PnP来获取SharePoint 2013服务器上的所有网站。
从管理中心,我可以将所有网站集查看为
/
/people/A
/people/B
...
网站网址就像
https://people-hr.mycompany.com
https://people-hr.mycompany.com/A/JohnAllen
https://people-hr.mycompany.com/A/SamAdams
https://people.hr.mycompany.com/B/JamesBell
...
使用
Connect-PnPOnline -Url "https://products.mycompany.com" -Credentials (Get-Credential)
or
Connect-PnPOnline -Url "https://products.mycompany.com/A/JohnAllen" -Credentials (Get-Credential)
我可以转到根站点或子站点。但是有很多站点。我需要获取所有站点,以便可以迭代它们进行一些数据维护。
我尝试使用Get-PnPSite和Get-PnPSubWebs(带有Recurse),但是它们无法返回所有站点。
解决方法
Get-PnPTenantSite将返回所有网站集。为了遍历每个,请尝试以下操作:
$cred = Get-Credential
Connect-PnPOnline "https://mytenant.sharepoint.com" -Credentials $cred
$SiteCollections = Get-PnPTenantSite
foreach ($SiteCollection in $SiteCollections)
{
Connect-PnPOnline -Url $SiteCollection.Url -Credentials $cred
Get-PnPSubWebs
}
,
您可以使用命令Get-PnPTenantSite
列出所有网站集。
参考: