Get SharePoint Site Collection, Web, List Objects from GUID

Requirement: On Nintex workflow databases, Ran a query to fetch workflow usage statistics, and the query gave GUIDs of SPSite, SPWeb and SPList objects!

How to Get SharePoint Site Collection, Web, List Objects from ID?

Our workflow reporting gave a bunch of GUIDs of sites, web and other objects.

SELECT TOP 100 
I.WorkflowName, 
I.WorkflowInstanceID, 
I.SiteID, 
I.WebID, 
I.ListID, 
I.ItemID, 
I.WorkflowInitiator, 
I.WorkflowID,
I.State, COUNT(P.WorkflowProgressID) as WorkflowProgressRecords
FROM WorkflowInstance I inner join WorkflowProgress P WITH (NOLOCK)
ON I.InstanceID = P.InstanceID
--WHERE i.State=2 
GROUP BY I.WorkflowName, I.WorkflowInstanceID, I.SiteID, I.WebID, I.ListID, I.ItemID, I.WorkflowInitiator, I.WorkflowID, I.State 
ORDER BY COUNT(P.WorkflowProgressID) DESC
Get SharePoint Site Collection, Web, List Objects from GUID

Well, from SQL query we got GUIDs of SharePoint site collection, web and list objects, but how do we get the actual site collection/site/list locations? PowerShell comes to rescue. Here is the PowerShell script to get SharePoint site collection, web, list objects from GUID.

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")  
 
#Get-SPWeb cmdlet for MOSS 2007
 Function global:Get-SPWeb($SiteGUID, $WebGUID)
{
  $site = New-Object Microsoft.SharePoint.SPSite($SiteGUID)
        if($site -ne $null)
            {
               $web=$site.OpenWeb($WebGUID);      
            }
    return $web
}
 #GUIDs for Site, Web and List 
 $SiteGUID = [GUID]("294D0050-19BE-439E-BF87-246F07828DAE")
 $WebGUID = [GUID]("AEDA6502-83C5-4967-A4C6-DF26B6F1ABDA")
 $ListGUID =[GUID]("1A54DCCD-251A-4B05-A7EC-BF10877C8B90")
 
 #Get the Web   
 $web = Get-SPweb $SiteGUID $WebGUID
 #Get the List
 $list = $web.Lists[$ListGUID]
 
 #Get the List title
 $list.title 
 $ListURL = $Web.URL+"/"+$list.RootFolder.URL
 write-host $ListURL 

Get List from List ID:
What if you have only list GUID and would like to get list details?

Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL | % {$_.Lists} | ? {$_.ID -eq "LIST-ID"} | Format-Table Title, ParentWebURL, RootFolder

Want to do the reverse? To get the GUID of SharePoint Site, List GUIDs, refer: Find the GUIDs of SharePoint Web Application, Site Collection, Site, List, View and Columns

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *