SharePoint 2010: Get List of All Web Applicatons/Site Collections/Sub-Sites/Permissions and Last Modified using PowerShell

#GET ALL WEB APPLICATIONS IN THE FARM

$webApp = Get-SPWebApplication

#FOREACH LOOP, LOOPING THROUGH ALL WEB APPLICATIONS IN THE FARM

foreach ($webApps in $webApp)

{

#WRITE-HOST WEB APPLICATION NAME

write-host “WEBAPP:” $webApps.Name

#FOREACH LOOP, LOOPING THROUGH ALL SITE COLLECTIONS WITHIN WEB APPLICATION

foreach ($site in $webApps.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

}

}

}

#FOREACH LOOP, LOOPING THROUGH ALL LISTS IN THE WEB

foreach ($list in $webs.Lists)

{

#WRITE-HOST LIST NAME AND LAST MODIFIED DATE

write-host “LIST NAME: ” $list.Title “| LAST MODIFIED DATE: ” $list.LastItemModifiedDate

}

}

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *