April 22, 2024

SamTech 365

PowerPlatform, Power Apps, Power Automate, PVA, SharePoint, C#, .Net, SQL, Azure News, Tips ….etc

List of SharePoint sites with list of users in %owner% Groups

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) > $null

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()

foreach ($websvc in $websvcs)
{
foreach ($webapp in $websvc.WebApplications)
{
foreach ($site in $webapp.Sites)
{
write-host $site.URL
foreach ($web in $site.AllWebs)
{
write-host $web.URL
foreach ($group in $web.Groups)
{
$G = $group.Name
if ($G -match “owner”)
{
write-host ”  –>” $G
foreach ($user in $group.Users)
{
write-host ”     –>” $user.Name
write-host “”
}
}
}
}
}

}
}
GO

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) > $null

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()

foreach ($websvc in $websvcs)
{
foreach ($webapp in $websvc.WebApplications)
{
foreach ($site in $webapp.Sites)
{
write-host $site.URL
foreach ($web in $site.AllWebs)
{
write-host $web.URL
foreach ($group in $web.Groups)
{
$G = $group.Name
if ($G -match “owner”)
{
write-host ”  –>” $G
foreach ($user in $group.Users)
{
write-host ”     –>” $user.Name
write-host “”
}
}
}
}
}

}
}
GO