Sunday, March 30, 2014

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!

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 



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...