0

So, I'm trying to write a script to iterate through all web apps, extract the groups & members from each site collection/child site and output to CSV.
I used Konstantin Vlasenko's function to extract group information. Works like a charm! What I'm trying to do now is get this to get all web apps, get all webs and then get all sites. Here's what I have so far but......so far all I get in my array is the code exported to CSV. I'm off somewhere. Can you see what I'm missing?

... {

CLS

$groups = @()
$webapps = Get-SPWebApplication
$sites = $webapps | Get-SPSite
$webs = $sites | Get-SPWeb
function Get-SPPermissionsRoles($web, $recursive){
foreach($webapp in $webapps)
{
#$sites = Get-SPSite $webapps
foreach($site in $sites)
{
{
$webs | Get-SPUser | % { New-Object PSObject -Property {
$grpobject = Add-Member -Name UserLogin = $.UserLogin
$grpobject = Add-Member -Name 'Roles given explicitly' = $
.Roles
$grpobject = Add-Member -Name 'Roles given via groups' = $.Groups | %{$.Roles}
$grpobject = Add-Member -Name Groups = $_.Groups
$grpobject = Add-Member -Name Url = $web.Url
$groups += $grpobject
}

          }  
          if($recursive) { $web.Webs | % { Get-SPPermissionsRoles $_ $recursive }   }  
        }  
    }  
}  
}  

Get-SPPermissionsRoles $webs $true | Export-Csv -Path "E:\Temp\Roles.csv"
$groups | Export-Csv "E:\temp\groups.csv"

}
...

0

Hope these articles are helpful to you:

SharePoint PowerShell to Get All Users in Farm

Export SharePoint Users and Groups to Excel using PowerShell

| improve this answer | |

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.