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

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-WebApplication

#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
}
}
}
}
}

Advertisements
  1. December 11, 2014 at 4:15 pm

    it has to be this

    #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
    }
    }
    }
    }

  2. Thomas Van Rompay
    May 20, 2015 at 3:07 pm

    And how do we export the results of this script in a CSV, TXT or …. file? Now i receive my results in the management shell but are so big, that it would be nice to receive them in a proper file.

    Thanks!

    • May 26, 2015 at 7:35 am

      Hi Tomas,

      You can export to .txt file easily by piping to a txt file where the write-host is called. See below.

      $filename = “c:\temp\lastmodified.txt”

      #GET ALL WEB APPLICATIONS IN THE FARM
      $webApp = Get-WebApplication

      #FOREACH LOOP, LOOPING THROUGH ALL WEB APPLICATIONS IN THE FARM
      foreach ($webApps in $webApp)
      {

      #WRITE-HOST WEB APPLICATION NAME
      write-host “WEBAPP:” $webApps.Name
      “WEBAPP: ” >> $filename

      #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
      $site.URL >> $filename

      #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)”

      “SITE COLLECTION ADMINS – $($siteAdmin.DisplayName)” >> $filename

      }

      #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

      “SUB-SITE NAME: ” >> $filename

      #WRITE-HOST SUB-SITES URL
      write-host “SUB-SITES URL:” $webs.URL

      “SUB-SITS URL: ” >> $filename

      #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

      “Permission Level: ” $roleDefinition.Name “| Permission Name: “#roleAssignment.Member.Name >> $filename

      }
      }
      }

      #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

      “LIST NAME: ” $list.Title ” | LAST MODIFIED DATE: ” $list.LastItemModifiedDate >> $filename
      }
      }
      }
      }
      }

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: