SharePoint Powershell script to get permission for all subsites.
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null){
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$webApps = Get-SPWebApplication "https://myportal.mysite.dev.mycompany.com"
foreach ($webApp in $webApps)
{
foreach ($site in $webApp.Sites)
{
#WRITE-HOST SITE COLLECTION URL
write-host “SITE: ” $site.URL
#FOREACH LOOP, LOOPING THROUGH ALL SITE COLLECTION ADMINISTRATORS
foreach ($siteAdmin in $site.RootWeb.SiteAdministrators)
{
#WRITE-HOST SITE COLLECTION ADMINS
write-host -foregroundcolor green “SITE COLLECTION ADMINS – $($siteAdmin.DisplayName)”
}
#FOREACH LOOP, LOOPING THROUGH ALL SUB-SITES IN SITE COLLECTION
foreach ($webs in $site.AllWebs)
{
#WRITE-HOST SUB-SITE NAME
write-host “SUB-SITE NAME:” $webs.Name
#WRITE-HOST SUB-SITES URL
write-host “SUB-SITES URL:” $webs.URL
#FOREACH LOOP, LOOPING THROUGH ALL ROLE ASSIGNMENTS IN THE WEB ROLE ASSIGNMENTS
foreach ($roleAssignment in $webs.RoleAssignments)
{
#FOREACH LOOP, LOOPING THROUGH ALL ROLE DEFINITIONS IN ROLE ASSIGMENT ROLE DEFINITIONS
foreach ($roleDefinition in $roleAssignment.RoleDefinitionBindings)
{
#IF STATEMENT (IF ROLE DEFINITION EQUALS FULL CONTROL)
#if ($roleDefinition.Name -eq “Full Control”)
#{
#WRITE-HOST PERMISSION LEVEL AND PERMISSION NAME
write-host -foregroundcolor red “Permission Level: ” $roleDefinition.Name “| Permission Name: “$roleAssignment.Member.Name
#}
}
}
}
}
}
write-host -foregroundcolor red “Script Over"