Get SharePoint List Name and GUID using PowerShell and CSOM

This SharePoint PowerShell tutorial explains, how to get a SharePoint list or document library GUIDs using PowerShell in SharePoint. The code will work to get SharePoint list GUID using PowerShell in SharePoint 2013/2016.

We will discuss how to GUID of a SharePoint 2013 list using browser and how to retrieve list name from guid using CSOM (.Net managed object model code) in SharePoint Online.

If you want to get the GUID of a SharePoint list you can easily get it from the browser or also you can get it by using a PowerShell command.

To get the GUID of a particular SharePoint list, Simply open the SharePoint list settings page using browser and then you will see something like below in the browser.

?List=%7BB13CC473-6187-4478-A0DD-853E83AA6F9D%7D

Here whatever presented after %7B and before %7D is your list GUID. In this particular case, the GUID of the SharePoint list will be: B13CC473-6187-4478-A0DD-853E83AA6F9D

Get SharePoint list guid PowerShell

Below is the PowerShell command which will give you the Guids of all SharePoint list and library of the site collection.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$site = Get-SPSite http://win-pfcp2dgt8di/sites/EnjoySharePoint/
$web = $site.RootWeb
$lists = $web.lists
$lists | Format-Table title,id -AutoSize

It will look like below:

get sharepoint list guid powershell

If you want to find out between generic list and document library then you can put the below command.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$site = Get-SPSite http://win-pfcp2dgt8di/sites/EnjoySharePoint/
$web = $site.RootWeb
$lists = $web.lists | Where-Object { $_.BaseType -Eq "GenericList" }
$lists | Format-Table title,id -AutoSize
$libraries = $web.lists | Where-Object { $_.BaseType -Eq "DocumentLibrary" }
$libraries | Format-Table title,id -AutoSize

Get List Name from GUID using PowerShell in SharePoint 2013/2016

Now, we will see how to get a list name from GUID using PowerShell in SharePoint 2013/2016.

Sometimes, you may need to retrieve the List name from the list GUID, PowerShell is the best option for the same.

Recently we got one error in ULS Logs, which display the GUID of the SharePoint list and we use PowerShell to get more about the list.

PowerShell Command to Get SharePoint List Name from GUID

Below is the PowerShell command which will return the List Name, Web URL and Root folder. You can run the PowerShell cmdlets in Windows PowerShell ISE.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

Get-SPSite http://win-pfcp2dgt8di/sites/EnjoySharePoint/ | Get-SPWeb -Limit ALL | %{$_.Lists} |?{$_.ID –eq "B13CC473-6187-4478-A0DD-853E83AA6F9D"} |ft Title, ParentWebURL, RootFolder

Now, you can see, the PowerShell cmdlets return information about the SharePoint list.

Get List Name from GUID using PowerShell in SharePoint

How to get GUID of a SharePoint 2013/2016/Online list

Now, we will see how to get GUID of a SharePoint list using a browser. It will work for SharePoint 2013/2016 or SharePoint Online.

Below is the step to get the SharePoint list ID:

Open the SharePoint list using the browser, then go to the list settings.

Now copy the URL from the browser and put it somewhere in the notepad.

http://win-pfcp2dgt8di/sites/EnjoySharePoint/_layouts/15/listedit.aspx?List=%7B58A98D82-3F9A-4FB6-8CA4-7DB31E233EB2%7D

Now notice whatever present after List= %7B58A98D82-3F9A-4FB6-8CA4-7DB31E233EB2%7D

That is the list ID but we need to format it like below:

  • Change “%7B” to “{“
  • Change all “%2D” to “-“
  • Change “%7D” to “}”

Now the ID should look like this: {58A98D82-3F9A-4FB6-8CA4-7DB31E233EB2}

This is your SharePoint list ID.

Retrieve list name from guid using CSOM in SharePoint Online

Now, we will discuss how to get the list name from list Guid by using .net managed object model (csom) code in SharePoint online.

Here we will do everything using console application and we will connect to SharePoint online site. Here we will pass a Guid of a list and it will return the name of the list in SharePoint Online.

To work with .Net client object model we need below dlls:

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.ClientRuntime.dll

We can add these dlls from Nuget package manager.

Below is the method which will take the SharePoint site URL and Guid of the list. Here GetById method will return the list and then we can retrieve the list title property from the Title property.

public static string GetListNameFromGUID(string URL, string GUID)
        {
            Guid guid = new Guid(GUID);
            string listName = string.Empty;
            ClientContext context = new ClientContext(URL);
            context.AuthenticationMode = ClientAuthenticationMode.Default;
            context.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());
            var web = context.Web;
            context.Load(web);
            List lst = context.Web.Lists.GetById(guid);
            context.Load(lst,l=>l.Title);
            context.ExecuteQuery();
            return lst.Title;
        }

private static SecureString GetSPOSecureStringPassword()
        {
            try
            {
                var secureString = new SecureString();
                foreach (char c in ConfigurationManager.AppSettings[“SPOPassword”])
                {
                    secureString.AppendChar(c);
                }
                return secureString;
            }
            catch
            {
                throw;
            }
        }

        private static string GetSPOAccountName()
        {
            try
            {
                return ConfigurationManager.AppSettings[“SPOAccount”];
            }
            catch
            {
                throw;
            }
        }

We can call the method like below:

string listName = GetListNameFromGUID("https://<tenantname>.sharepoint.com/sites/Bhawana/", "C6D7A7EB-09C0-4E45-B4D8-03C523FEE16D");

Once you run the above code, you can see the result, it will display the list name based on Guid.

You may like following PowerShell SharePoint tutorials:

This SharePoint tutorial, we discussed how to get SharePoint list Guids using PowerShell in SharePoint 2013/2016.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

>