6/15/2011

Finding SharePoint GUIDs using PowerShell

 

Two years or so ago I posted an article on how to find site, web and list GUIDs using a console application or an _LAYOUTS application page. Here’s a little update to do the same thing with a few lines of PowerShell.

New! Finding SharePoint 2013 GUIDs using REST: http://techtrainingnotes.blogspot.com/2014/02/sharepoint-2013-and-office-365-finding.html

2007 version:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = New-Object Microsoft.SharePoint.SPSite("http://yourserver/sites/yoursite")
$web = $site.OpenWeb("yoursubsite")
write-host "Site: " + $site.id
write-host "Web: " + $web.id
$web.lists | Format-Table title,id -AutoSize
$web.Dispose()
$site.Dispose()

2010 version:

$site = Get-SPSite http://yourserver/sites/yoursite
$web = $site.OpenWeb("yoursubsite")
write-host "Site: " + $site.id
write-host "Web: " + $web.id
$web.lists | Format-Table title,id -AutoSize
$web.Dispose()
$site.Dispose()

Note: You could change $site.OpenWeb("yoursubsite")  to $site.RootWeb to get just the top site.

 

Here’s what the output looks like:

image

 

.

13 comments:

Anonymous said...

I am a SharePoint admin for my organization. We recently had Microsoft come do a health check. Long story short, we have some GUIDs of some orphaned webs. Do you know how I might go about using that GUID to determine which site the web is part of? Basically I need to do something in powershell that lets me enter the GUID and have it display the URL of the web/site collection in question.

Mike Smith said...

Depends on how it was orphaned. Did they say they were site GUIDs?

Check back late tonight or tomorrow and I'll post a search by GUID PS script.

Mike

Mike Smith said...

To find a site by its GUID:

Get-SPWebApplication |
get-spsite -Limit All |
get-spweb -Limit All |
where { $_.Id -eq "b74081c8-4dc9-42a6-a1f3-bfa9c82a17f3" } |
select url

But if you want to find and delete orphans then check these:

http://www.sharepointjoel.com/Lists/Posts/Post.aspx?List=0cd1a63d-183c-4fc2-8320-ba5369008acb&ID=291

http://sharenotes.wordpress.com/2007/11/19/deleting-purging-removing-orphaned-sites-or-site-collections/

Mike

Anonymous said...

So I'm running that and getting an error "Get-SPWeb: Access is denied". I looked around online and some people suggested an issue with rights in SQL. I have farm admin rights and have full SQL rights as well.

Any ideas?

Anonymous said...

Ok, so we found that the problem was that a new webapp didn't have the same rights assigned to it as the others. We took care of that, but now when I run the commands nothing happens. It thinks for a while then returns to the cursor.

Mike Smith said...

Anonymous

> permissions...

To use PowerShell against SharePoint you need several levels of permissions. See here for more info:
http://techtrainingnotes.blogspot.com/2011/08/searching-and-auditing-sharepoint-with.html

Mike

Thuba said...

Hi Mike. Thanks for the great post. Is there a way to find the web ID of an O365 Website?

Mike Smith said...

Thuba,

Yes, use REST...

Visit and log on to the O365 site.
Edit the URL like so:

https://yourdomain/sites/yoursite/_api/web

In the XML that is returned find the line like this one:

f923f6a9-7906-44e6-a19c-a1dc895570a1

Mike

Mike Smith said...

Thuba,

Here's a little article on using REST to find the GUIDs (and other goodies!).

http://techtrainingnotes.blogspot.com/2014/02/sharepoint-2013-and-office-365-finding.html

Mike

Unknown said...

Hi there

What's the best way to get GUIDs for all document libraries in the entire site?

E.g. put in top level URL and it goes through all subsites, and also a way to narrow results to just document libraries.

Thanks!

Mike Smith said...

Matt,

Try this to find all libraries based on the "DocumentLibrary" template in an entire site collection:

Get-SPSite http://yourserver/sites/yoursite | Select -ExpandProperty AllWebs | Select -ExpandProperty Lists | Where { $_.BaseTemplate -eq "DocumentLibrary" } | Select Title, ParentWebUrl, Id

Mike

Unknown said...

Hi Mike

Thanks for the fast response! Just to confirm, would I put that code into powershell on the server, or can I run it in powershell on my local machine?

Cheers,
Matt

Mike Smith said...

Matt,

It must be run on a SharePoint server, directly or via PowerShell remoting.

Mike

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.