Get a directory of all list name based on list IDs from lists in all sites in a site collection in SharePoint Online

Yiru Chen 681 Reputation points
2021-04-05T18:18:07.377+00:00

We need to generate a directory of ListNames by know ListIDS of all lists from all sites (top and subsites) in a site collection, the output needs to show the list name and listID for each record. We already have list of ListIDs (from Audit Report) but not corresponding ListNames

Is there a way to generate such output? Poweshell?

I found a powershell command that can retrieve a list name by List ID: https://global-sharepoint.com/sharepoint-online/get-sharepoint-list-url-by-list-id/

But we have to retrieve list of listnames by list of ListIDs.

Appreciate anyone give a tip!

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,607 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 47,966 Reputation points
    2021-04-05T19:26:36.85+00:00

    If you already have a list of IDs and the script to get the name for a single ID then just use a foreach to call it for each one. The perf may be bad if the list is large though.

    $ids = @(123, 456, 789)
    foreach ($id in $ids) {
       $result = Get-SPSite ...
    
       # Store whatever data you need from the result associated with the ID it was called against
    }
    

    Taking a look at the call they are making though it seems like you could just call it once and then change the filter logic to look in your list instead. This would increase performance but requires that the Get-SPWeb call contain all the IDs you're looking for.

    $ids = @(123, 456, 789)
    
    Get-SPSite "http://SharePointserver/sites/TestSite/" | Get-SPWeb -Limit ALL | %{$_.Lists} |?{$ids -contains $_.ID } |ft Title, ParentWebURL, RootFolder
    

    You'll need to play around with the command to get the exact output you want though. At a minimum I suspect you'll want to ensure that the ID is returned back in addition to Title so you can match them up properly.