0

I have this PnP Power-shell to loop through all sites >> then all libraries >> then list all the main folders inside the libraries.

$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)
               {
               #Get all Subfolders of a folder - recursively
              $SubFolders = Get-PnPFolderItem -FolderSiteRelativeUrl $Library.RootFolder.ServerRelativeUrl -ItemType Folder #-Recursive
               
               ForEach($folder in $SubFolders)
               {
               
                Write-Host $Site.Title " --> "  $Library.RootFolder.ServerRelativeUrl " --> " $folder.Name " --> " $folder.ServerRelativeUrl
                $csvOutput +=  [PsCustomObject]@{SiteTitle = $Site.Title; LibraryTitle = $Library.RootFolder.ServerRelativeUrl; Folder = $folder.Name; FolderPath = $folder.ServerRelativeUrl}

               }
               
               }
}
 
 
}
$csvOutput | Export-Csv -NoTypeInformation -Path "D:\export123.csv"

The script is working fine, but i am getting this warning:-

WARNING: Parameter 'Web' is obsolete. The -Web parameter will be removed in a future release. Use Connect-PnPOnline -Url [subweburl] instead to connect to a subweb.

so what i need to modify to make my code future proof?

Thanks

2 Answers 2

1

The -Web parameter is no longer a listed parameter on the Get-PnPList documentation. I would suggest you not use this parameter and instead use the -Identity parameter, as defined in the documentation for this cmdlet.

9
0

I would be something like

ForEach($Web in $Webs) {
    $webConn = Connect-PnPOnline -Url $web.Url -ClientId $clientID -ClientSecret $clientSecret -returnConnection
    $DocumentLibraries = Get-PnPList -connection $webConnection | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Title -ne "Site Assets" -and $_.Hidden -eq $false}

You'd not to authenticate interactively for every web, so app credentials is used

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.