Skip to content

Instantly share code, notes, and snippets.

@devendrasv
Last active December 23, 2015 10:19
Show Gist options
  • Save devendrasv/6621125 to your computer and use it in GitHub Desktop.
Save devendrasv/6621125 to your computer and use it in GitHub Desktop.
Get Site collection and sub site last modified date and size in a web application
#constructing table
$a = "<style>"
$a = $a + "BODY{background-color:#ffffff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: ;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:wheat}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "</style>"
#Getting the list of site collection from the webapplication and stroing in an array
[array]$sites= get-spwebapplication http://sharepoint-journey.com| get-spsite -Limit All
#Variables
$count=0
$webcount=0
#Looping through each sitecollection
foreach($site in $Sites)
{
$count=$count + 1
#Getting the site collection Title,Url,Last Modified Date and Size. Later adding that to the html file.
$site | select @{label = "Title";Ex = {$_.rootweb.Title}} , url , @{label = "LastModifiedDate";Ex = {$_.lastcontentmodifieddate}} , @{label = "size";Ex = {$_.usage.storage/1MB}} | ConvertTo-HTML -head $a -body "<H4>Site Collection :$site</H4>" | Add-content C:\Sitecollectionandsubsites.html
#Getting the list of sub sites in a sitecollection
$Webs= get-spweb -site $site -Limit All
#Looping through each sub site
foreach($web in $webs)
{
#Getting the list details from the site
$lists= $web.Lists
$webcount= $webcount +1
#Getting the sub site Url, Title, Template and appedning the details to the created html file.
$web | select Url , Title , Webtemplate| ConvertTo-HTML -head $a -body "<H4>Websites in the site collection :$site</H4>" | Add-content C:\Sitecollectionandsubsites.html
#Getting the List Name and Last Modified Date which are not hidden
$lists | where{!($_.Hidden)} | select Title, @{label = "LastModifiedDate";Ex = {$_.LastItemModifiedDate}} | sort -desc LastItemModifiedDate | ConvertTo-HTML -head $a -body "<H4>List details in this :$web</H4>" | Add-content C:\Sitecollectionandsubsites.html
}
add-content C:\Sitecollectionandsubsites.html "<br>"
add-content C:\Sitecollectionandsubsites.html "<b>"
add-content C:\Sitecollectionandsubsites.html "<font color=black>"
add-content C:\Sitecollectionandsubsites.html "Total Number of Webs in the site collection is $webcount"
add-content C:\Sitecollectionandsubsites.html "</font>"
add-content C:\Sitecollectionandsubsites.html "</b>"
add-content C:\Sitecollectionandsubsites.html "<br>"
add-content C:\Sitecollectionandsubsites.html "<b>"
add-content C:\Sitecollectionandsubsites.html "<font color=black>"
add-content C:\Sitecollectionandsubsites.html "----------------------------------------------------------------------------------------------------------------------------"
add-content C:\Sitecollectionandsubsites.html "</font>"
add-content C:\Sitecollectionandsubsites.html "</b>"
}
add-content C:\Sitecollectionandsubsites.html "<br>"
add-content C:\Sitecollectionandsubsites.html "<b>"
add-content C:\Sitecollectionandsubsites.html "<font color=black>"
add-content C:\Sitecollectionandsubsites.html "Total Number of site collection is $count"
add-content C:\Sitecollectionandsubsites.html "</font>"
add-content C:\Sitecollectionandsubsites.html "</b>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment