1

Is it possible to get all users in a subsite. I found a script online but I keep getting the URL/ID cannot be found. The same command essentially works for the site collection but it doesn't work on the subsite.

Get-SPSite http://server/sites/yoursite |
 Select -ExpandProperty RootWeb |
 Select -ExpandProperty Groups |
 Where {$_.Name -EQ "your group name here"} |
 Select -ExpandProperty Users |
 Select Name, Email

Can someone put me in the right direction? Thank you.

1
  • Groups belongs to Root Site Collection. Jan 26 '15 at 21:12
4

The error you get with your code when used for a subsite is because you use Get-Site with a subsite Url. Instead of Get-SPSite use Get-SPWeb as below:

Get-SPWeb http://server/sites/yoursite |
Select -ExpandProperty Groups |
Where {$_.Name -EQ "your group name here"} |
Select -ExpandProperty Users |
Select Name, Email

The code above will find the group only if its created in that site. To find a group regardless where it's been created (root site or subsite) you have to use SiteGroups instead of Groups

Get-SPWeb http://server/sites/yoursite |
Select -ExpandProperty SiteGroups |
Where {$_.Name -EQ "your group name here"} |
Select -ExpandProperty Users |
Select Name, Email
1
  • My issue was, like you said, using Get-SPSite instead of Get-SPWeb. I also had to remove the Select -ExpandProperty RootWeb command. Thanks. Jan 27 '15 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.