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. Also, we will see how to Get SharePoint list created date using PowerShell.

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 is 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 lists and libraries 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
sharepoint powershell get list

If you want to find out between the generic list and the 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

Read Cannot contact web site or the web site does not support sharepoint online credentials

See also  Difference between SharePoint list and Document library

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 displays 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
powershell get sharepoint list

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 the 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.

Get SharePoint list created date using PowerShell

Now, ler us see how to get the SharePoint list created date using PowerShell. The same PowerShell code, we can use to get list created date using PowerShell in SharePoint 2013/2016.

See also  How to Update SharePoint list items using Power Automate?

There is not out of box direct way to get the list created date in SharePoint 2013/2016/Online. But there is a way to get the list created to date using PowerShell.

Get SharePoint list created date using PowerShell

In this example I have a SharePoint site in which I have a SharePoint list name Testing, I want to retrieve the created date of the list using PowerShell.

Add-PSSnapin Microsoft.Sharepoint.Powershell
$web = Get-SPWeb “http://win-pfcp2dgt8di/sites/EnjoySharePoint/”
$list = $web.lists[“Testing”]
$listCreatedDateTime = $list.Created
$web.Dispose()
$web = $null
Write-Host $listCreatedDateTime

The PowerShell command looks like below:

Get SharePoint list created date using PowerShell
Get SharePoint list created date using PowerShell

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 the 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 the 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.

See also  How to allow anonymous read access to a SharePoint site?

You may like the following PowerShell SharePoint tutorials:

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

  • sharepoint powershell get list
  • PowerShell get sharepoint list
  • powershell sharepoint list
  • get sharepoint list Powershell
>