question

YiruChen-1261 avatar image
0 Votes"
YiruChen-1261 asked ElsieLu-MSFT commented

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

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!

office-sharepoint-online
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @YiruChen-1261 ,

If you think cooldadtx's suggestion is helpful, you could mark it as an answer. It will help others who meet the similar question in this forum. Also others will directly see the answer.

Thanks,
Elsie Lu

0 Votes 0 ·

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered cooldadtx commented

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.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the tips.

Two questions:

  1. can I put list of IDs in a file and refer to that file in the command rather than actual IDs?

  2. What about generate a directory of All ListID with matching listNames in all Sites in the Site Col in the output? Is it possible?


0 Votes 0 ·

Yes you can put the IDs whereever you want. However to use them in the command you'll have to load them into memory. You can easily do that in Powershell. The Get-Content command allows you to read a file into memory as a string array. Assuming 1 line per ID you can then use the earlier code that was given.

0 Votes 0 ·

To enumerate all the sites and directories you're going to have to make some API calls to SharePoint. You can find the docs here. You'll need to play around with the API calls to find what you need exactly. Postman is a useful tool for playing around with REST APIs easily but you can also just stick with Powershell and the Invoke-WebRequest command.

0 Votes 0 ·