Below is a simple script to retrieve the SharePoint webapplication last modified details along with the site/subsite URL and folder size.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$siteInfo = @();
Get-SPWebApplication http://yourwebapplication/ | Get-SPSite -Limit All | Get-SPWeb -Limit All|%{
$web = $_;
$listInfo = ""
$versionCount = ""
$strHomePage = $web.RootFolder.WelcomePage
$WebSize = CalculateFolderSize($Web.RootFolder)
$row = New-Object -TypeName PSObject
$row | Add-Member -Name 'Site' -MemberType Noteproperty -Value $web.Title
$row | Add-Member -Name 'URL' -MemberType Noteproperty -Value $web.Url
$row | Add-Member -Name 'LastModifiedDate' -MemberType Noteproperty -Value $web.LastItemModifiedDate.tostring('dd/MMM/yyyy')
$row | Add-Member -Name 'Size' -MemberType Noteproperty -Value $WebSize
$siteInfo += $row
}
$siteInfo | Export-CSV "D:\SiteName.csv" -NoTypeInformation
Function CalculateFolderSize($Folder)
{
[long]$FolderSize = 0
foreach ($File in $Folder.Files)
{
#Get File Size
$FolderSize += $file.TotalLength;
#Get the Versions Size
foreach ($FileVersion in $File.Versions)
{
$FolderSize += $FileVersion.Size
}
}
#Iterate through all subfolders
foreach ($SubFolder in $Folder.SubFolders)
{
#Call the function recursively
$FolderSize += CalculateFolderSize $SubFolder
}
return $FolderSize
}
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$siteInfo = @();
Get-SPWebApplication http://yourwebapplication/ | Get-SPSite -Limit All | Get-SPWeb -Limit All|%{
$web = $_;
$listInfo = ""
$versionCount = ""
$strHomePage = $web.RootFolder.WelcomePage
$WebSize = CalculateFolderSize($Web.RootFolder)
$row = New-Object -TypeName PSObject
$row | Add-Member -Name 'Site' -MemberType Noteproperty -Value $web.Title
$row | Add-Member -Name 'URL' -MemberType Noteproperty -Value $web.Url
$row | Add-Member -Name 'LastModifiedDate' -MemberType Noteproperty -Value $web.LastItemModifiedDate.tostring('dd/MMM/yyyy')
$row | Add-Member -Name 'Size' -MemberType Noteproperty -Value $WebSize
$siteInfo += $row
}
$siteInfo | Export-CSV "D:\SiteName.csv" -NoTypeInformation
Function CalculateFolderSize($Folder)
{
[long]$FolderSize = 0
foreach ($File in $Folder.Files)
{
#Get File Size
$FolderSize += $file.TotalLength;
#Get the Versions Size
foreach ($FileVersion in $File.Versions)
{
$FolderSize += $FileVersion.Size
}
}
#Iterate through all subfolders
foreach ($SubFolder in $Folder.SubFolders)
{
#Call the function recursively
$FolderSize += CalculateFolderSize $SubFolder
}
return $FolderSize
}
Comments
Post a Comment