我有这个脚本循环通过所有网站集〉〉和所有文档库〉〉然后列出文件夹在这种格式“网站名称〉〉列表名称〉〉文件夹名称”:-
$AdminUrl = "https://*****-admin.sharepoint.com/"
Connect-PnPOnline -Url $AdminUrl -Interactive
#sharepoint online get all site collections PowerShell
$SiteColl = Get-PnPTenantSite
#sharepoint online PowerShell iterate through all site collections
ForEach($Site in $SiteColl)
{
Connect-PnPOnline -Url $Site.Url -Interactive
$Webs = Get-PnPSubWeb -Recurse -IncludeRootWeb
#Get All document libraries
ForEach($Web in $Webs)
{
$DocumentLibraries = Get-PnPList -Web $Web | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Title -ne "Site Assets" -and $_.Hidden -eq $false}
#Iterate through each document library
ForEach($Library in $DocumentLibraries)
{
$f = Get-PnPFolder -List $Library
ForEach($folder in $f)
{
Write-Host $Site.Title " --> " $Library.Title " --> " $folder.Name
}
}
}
}
但我面临的问题是,Get-PnPFolder -List $Library
将得到所有的主文件夹和子文件夹..那么我怎么能限制这个命令只得到主文件夹(第一级文件夹)没有子文件夹?
谢谢
编辑以下是更新后的脚本:-
$AdminUrl = "https://***-admin.sharepoint.com/"
Connect-PnPOnline -Url $AdminUrl -Interactive
#sharepoint online get all site collections PowerShell
$SiteColl = Get-PnPTenantSite
$csvOutput = @()
#sharepoint online PowerShell iterate through all site collections
ForEach($Site in $SiteColl)
{
Connect-PnPOnline -Url $Site.Url -Interactive
$Webs = Get-PnPSubWeb -Recurse -IncludeRootWeb
#Get All document libraries
ForEach($Web in $Webs)
{
$DocumentLibraries = Get-PnPList -Web $Web | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Title -ne "Site Assets" -and $_.Hidden -eq $false}
#Iterate through each document library
ForEach($Library in $DocumentLibraries)
{
$f = Get-PnPFolder -List $Library
ForEach($folder in $f)
{
Write-Host $Site.Title " --> " $Library.Title " --> " $folder.Name " --> " $folder.ServerRelativeUrl
$csvOutput += [PsCustomObject]@{SiteTitle = $Site.Title; LibraryTitle = $Library.Title; Folder = $folder.Name; FolderPath = $folder.ServerRelativeUrl}
}
}
}
}
$csvOutput | Export-Csv -NoTypeInformation -Path "D:\export123.csv"
并且csvOutput将具有如下值:-
NewRoot --> dv --> test123 --> /dv/test123
NewRoot --> dv --> P100 --> /dv/P100
NewRoot --> dv --> WIP --> /dv/P100/WIP
NewRoot --> Site Pages --> Templates --> /SitePages/Templates
NewRoot --> tagggg --> a1 --> /tagggg/a1
NewRoot --> tagggg --> a2 --> /tagggg/a1/a2
NewRoot --> testdcdc --> test --> /testdcdc/test
1条答案
按热度按时间c2e8gylq1#
好的,根据我们的评论,我认为你想做的是这样的。
它遍历整个文件夹列表,但使用哈希表来确保您只收集顶级文件夹的唯一列表。