Using PowerShell to access SharePoint Sites, Users, and Groups – David Lozzi Skip to content Search Search for: David Lozzi Geek Menu Home Advent Of Code My Apps Dear Me Speaking & Community Office 365 Forms Planner Power Apps Power Automate (Flow) SharePoint Online SharePoint Calendars Teams About How Can I Help? Open Search Using PowerShell to access SharePoint Sites, Users, and Groups In this post I am going to dive into some of the basics of accessing your SharePoint sites using PowerShell. This is a pretty basic concept, but something that I think is worth knowing. Understanding the basics allows us to dive deeper into the more complex stuff. So let’s start! On one of the SharePoint servers, open your SharePoint 2010 Management Shell (Start > All Programs > Microsoft SharePoint 2010 Products). You may have to right click on the app and select Start as Administrator to get the correct permissions. You will get a nice black window, type in cd\ to get to the root. This gives us a little more room to work with. At any time, you can type in cls to clear the screen, this is helpful to keep your eyes focused. First things first, let’s get a site collection. Type in the following, followed by the Enter key $site = Get-SPSite http://yoursitename Now the $site object is your site collection. If it worked correctly, you’ll just be returned to the command prompt Let’s make sure you have the right site, so lets check the URL. Type in the following and press enter after $site.URL And that should return your address to the site collection. Want to see all webs in your site? Type in $site.allwebs Pretty neat eh? You can get the site owner now $site.owner You can explore the site object and all of its properties and methods by referencing MSDN article http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite_properties.aspx . Initially we used the Get-SPSite command to get a site. If you leave the address off, and just type in get the command, we can get all sites back get-spsite Using the previous reference to MSDN, we can add additional properties for a nice report. Let’s pull all site collections with their associated content database. get-spsite | format-table -property URL,contentdatabase And you’ll see all my site collections are in the same database. Ok, back to our first $site. Now let’s get the root web and check the name. $root = $site.rootweb $root.title You just got your first site! Good job! There’s a slightly faster way to get a website. Instead of getting the site then getting the web, you can just call Get-SPWeb http://youraddress, and that will return the web for you. So if you want to grab a subsite, you would call $web = Get-SPWeb http://address/site/site/site Now that you have a web, you can explore it’s properties and find out some more information about it. Check out MSDN article: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb_properties.aspx. Back to our $root. Let’s get a list of all users in the web. $root.allusers Next, let’s see who’s a site admin, and whether or not any of these users are domain groups. $root.allusers | format-table -property displayname, issiteadmin, isdomaingroup The additional properties, issiteadmin, isdomaingroup, are from the SPUser object (see http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser_properties.aspx for more detail). Let’s check out the groups of the site. $root.groups | format-table -property name, owner, users If you run just $root.groups (try it) it’ll dump out a lot of information at once. Formatting and selecting our data makes it easier to work with. The above results tells us the groups of the site, and who owns it, and a sneak peak of the users within the group. Let’s explore one group to see all of the users in it. $group = $root.groups["Sideswipe Members"] $group.users To get a user, you need to know the user’s ID or email address. To find this info, you can add the properties to the above command $group.users | format-table -property displayname, id, email No, my users do not have email addresses, so I’ll have to use the ID. Either way, you would use $user = $group.users.getbyemail("emailaddress") or $user = $group.users.getbyid(17) Confirm you have the right users $user.displayname This was a very top level overview of accessing some of SharePoint’s objects. From here, now that you know how to get some of the common objects, you can query some more, update values and properties, add users to groups, etc. Microsoft’s MSDN site is extremely helpful in exploring these objects. Please leave a comment below if you want to see something more specific. Please share the love! Click to share on Twitter (Opens in new window) Click to share on Facebook (Opens in new window) Click to share on LinkedIn (Opens in new window) Click to email a link to a friend (Opens in new window) More Click to print (Opens in new window) Click to share on Reddit (Opens in new window) Click to share on Pocket (Opens in new window) Click to share on WhatsApp (Opens in new window) Click to share on Skype (Opens in new window) Like this: Like Loading... March 7, 2012 SP2010 Administration Groups, Permission Management, PowerShell, SharePoint, site collection, sites, spsite, spweb, User Management, Users Post navigation Loading SharePoint lists from Excel using PowerShell SharePoint 2010 Web Parts and Their Features 15 thoughts on “Using PowerShell to access SharePoint Sites, Users, and Groups” Add yours Samet says: August 10, 2016 at 5:19 am Thnx. It was very Helpfull. Loading... Reply CJ says: July 19, 2016 at 6:51 pm I’d love a point in the right direction for getting more info about authors. Counting the number of edits they’ve made in total (given we’ve got workflow on, and we always approved, I don’t think ‘published by’ will quite do the trick). Loading... Reply David Lozzi says: August 1, 2016 at 8:50 am You’ll need to either look at the workflow history, and see the comments to determine what changed when or look at the item history (if you have versioning turned on) and look through there for who changed what when. Or both? Email me and we can continue the discussion, david.lozzi at slalom.com. Thanks! Loading... Reply Bill says: June 30, 2016 at 10:17 am Well done Loading... Reply Saumya says: April 7, 2016 at 7:06 pm Awesome one. Helped me a lot Loading... Reply Larry W. Virden says: April 29, 2014 at 7:33 am I really appreciate this blog post. Your style of writing is excellent. I find things like this to be great to someone like me who is trying to learn how best to use powershell in the day to day sp2010 administration. Have you ever worked on the use of PowerShell and workflows? I occasionally get bounced mail in the farm admin mailbox when a workflow task was assigned to a user who either is no longer at the company or their mailbox is full, etc. There is not enough info in the bounce to tell where in the farm the workflow is, so I can’t determine what site admin to contact about the issue. I was hoping that powershell might be able to be used to find the URLs of farm active workflows and the potential task assignees defined within those active workflows . That would allow me to determine whether any of the workflows need to be updated . Thanks for any ideas. Loading... Reply David Lozzi says: April 29, 2014 at 8:26 am That is a great idea! I haven’t targeted workflows with PowerShell yet, but it should be pretty straight forward. If you’re familiar with C#/PowerShell, you can probably get some pointers from the source code on my CodePlex project, https://sp2010adminpack.codeplex.com/wikipage?title=Workflow%20Manager&referringTitle=Home. This web part lists all workflows and their associated details. From there, you may be able to dive into the workflow actions, but I’m guessing not. You should be able to at least iterate through the associated tasks and who they’re assigned to. I like this idea and will load it up on my to do list, but there’s a lot there, I can’t say when I’d get it done. Loading... Reply Larry W. Virden says: April 29, 2014 at 11:30 am Thank you for your reply. I don’t have any familiarity with C#, and my powershell knowledge is pretty rudimentary. Thank you for the pointer – I will have to see whether your codeplex project provides the information I am seeking. Thank you again for your kindness. Loading... Reply Keith Vollero says: February 4, 2014 at 3:31 pm I’ve been banging around PowerShell sites for a month, looking for answers and hints, and this is the clearest explanation of the most valuable basic information I’ve seen anywhere, including books on the topic. Thanks and Kudos. Loading... Reply David Lozzi says: February 4, 2014 at 3:34 pm Thanks for your kind words, I’m glad I could help! Loading... Reply Mike says: June 13, 2013 at 7:11 pm I have some groups within groups, How would I get those group members? Specificaly I have “Builtin\Administrators” as a user in Farm Administrators. Loading... Reply David Lozzi says: June 14, 2013 at 4:40 pm Getting users out of AD groups will require you to traverse AD. I have some code somewhere, I’ll have to find it and post it. I don’t know however if that’ll traverse Builtin\Administrators, as that’s not an AD group, it’s more of a Windows Server thing. I guess I’ll try and find out. Give me a few days to get the post together. I’ll reply again here. Thanks, David Loading... Reply mikef2691@gmail.com says: June 15, 2013 at 10:46 am Thanks, Sent from my HTC Inspire™ 4G on AT&T Loading... Reply Stuart says: April 4, 2013 at 11:18 am Great article, thank you but how would I put a wildcard in here, $group = $root.groups[“WILDCARD Members”]? Loading... Reply David Lozzi says: April 8, 2013 at 8:53 am I don’t think wildcards are possible in the name, the array is looking specifically for a name. You could loop through all groups. Loading... Reply Leave a Reply to CJ Cancel reply Subscribe Enter your email address to subscribe to this blog and receive notifications of new posts by email. Email Address Sign me up! Join 1,342 other subscribers Disclaimer If it’s not obvious, this is a personal blog. Everything I write here represents my own findings and opinions, and not those of my employer. Feeds RSS - Posts RSS - Comments Popular Tags Advent Of Code community customization data design development internet explorer javascript lists Microsoft Power Automate (Flow) mobile O365 Office 365 performance Power Automate (Flow) PowerShell search SharePoint SharePoint Online Users Popular Categories Community JavaScript Microsoft Power Automate (Flow) Microsoft Teams Office 365 SharePoint Online SharePoint 2013 Administration SharePoint 2013 Development SP2010 Administration SP2010 Customization Users Don't Like SharePoint Categories CMS Collaboration Community Conference Consulting CSS Enterprise Git Java JavaScript Microsoft Forms Microsoft Planner Microsoft Power Apps Microsoft Power Automate (Flow) Microsoft Teams Microsoft To-Do Mobile Office 365 Hybrid Office 365 SharePoint Online Other Apps PHP Productivity Rant ReactJS SharePoint 2013 Administration SharePoint 2013 Apps SharePoint 2013 Development SP2010 Administration SP2010 Authentication SP2010 Customization SP2010 Infrastructure SP2010 User SP2010 Workaround SP2013 Uncategorized Users Don't Like SharePoint Website Top Posts & Pages Debugging Safari/Chrome on your iPhone/iPad/iOS device Sending a beautifully formatted email from Power Automate (Flow) Saving data from Microsoft Forms into Excel using Power Automate (Flow) Use Microsoft Forms to collect data right into your Excel file When Power Automate (Flow) can't find your Microsoft Form Understanding Power Automate's Outlook Send Email Actions Squeezing a little more formatting out of Microsoft Forms Tracking usage analytics within your Power Apps Enhancing reducer actions in React Context Embedding your JavaScript into a SharePoint page Follow GitHub Stack Overflow Twitter LinkedIn RSS - Posts Blog Stats 1,805,230 hits Up ↑ Loading Comments... Write a Comment... Email (Required) Name (Required) Website %d bloggers like this: