0

I am using powershell command remotely to communicate with SharePoint Server(2010/13 both). I am using following powershell command to fetch "SiteGroups" from site collections

Get-SPSite http://server/sites/yoursite |
  Select -ExpandProperty RootWeb |
  Select -ExpandProperty SiteGroups |
  Select {$_.ParentWeb.Url}, Name

But groups which are in a subsite inside a site collection also shown ParentWeb.Url as site collection URL. I want subsite's absoulte URL for those groups as those are belonging to subsite.

Can anybody suggest how to use get-spsite command to achieve this ? Does ParentWeb has any property which can give me absoulte URL of subsite ?

1 Answer 1

0

You should try something like this:

function GetGroups($web)
{
    foreach ($g in $web.Groups) {
        Write-Host $web.Url, $g.Name
    }   
    foreach ($w in $web.Webs) {
        GetGroups($w)
    }   
}

It is a recursive function that visits all your webs and writes the groups related to the webs. Execute the function, and then execute the following code, to call the function:

$web = Get-SPWeb http://server/sites/yoursite
GetGroups($web)
2
  • Thanks for your inputs .. but I forgot to mention , I want commands only as I will be firing it through .NET/C# application so don't have luxury to use script inside a C# application.
    – BND
    Jan 31, 2017 at 6:37
  • Ok, no problem. You'll definitely need some sort of recursive call since you need to check groups of every subweb in the structure. Jan 31, 2017 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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