Forum Discussion

jean090681's avatar
jean090681
Copper Contributor
Nov 16, 2021

Get all Libraries With No Retention Label

I need a help with PowerShell to generate a report with list of all the Libraries With No Retention Label from the SharePoint tenant Does anyone have a script

 

Is there any way to loop this to all the sites & library's in the tenant

Get-PnPLabel [-List ] [-Raw] [-Connection ]  https://github.com/pnp/powershell/blob/dev/documentation/Get-PnPLabel.md

 

Thank you

1 Reply

  • HerschelJ's avatar
    HerschelJ
    Brass Contributor

    I am setting off to do the same thing, here is what I have for all libraries in a site. You'll just need to add foreach Site in AllSites...

    #Parameters
    $SiteURL = "https://changeme.sharepoint.com/sites/siteA"
     
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
    
    #Get the Root Web
    $Web = Get-PnPWeb
    
    #Get all lists
    $Lists = Get-PnPList
    
    #exclude system lists
    $systemLibs = @("Form Templates","Site Assets", "Site Pages", "Style Library")
    
    foreach ($list in $Lists) {
        if ($list.Hidden -eq $true) {
            Write-Host "  Skipped hidden: " $list.Title -ForegroundColor Gray
        } else {
            if ($systemLibs.Contains($list.Title)) {
                Write-Host "  Skipped system lib: " $list.Title -ForegroundColor Gray
    
            } else {
               Write-Host $list.Title -ForegroundColor Yellow
                Get-PnPLabel -List $list #-ValuesOnly "TagName"
    
            }
    
        }
    }
    
    Disconnect-PnPOnline  #Friends dont let friends leave connections open

Resources