At some point, SharePoint Admins may need to obtain a web application's information, like total sites underneath, size of each site, total list count, site admin's login name, site owners, site URL etc.

The below PowerShell script does the job at one shot and exports the data into .CSV.

You can customize the script based on your requirement.

  1. If((Get - PSSnapIn - Name Microsoft.SharePoint.PowerShell - ErrorAction SilentlyContinue) - eq $null) {
  2. Add - PSSnapIn - Name Microsoft.SharePoint.PowerShell
  3. }
  4. #using the reflection assembly
  5. [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  6. # Give the Web Application Name
  7. $webApp = 'http://webappname'
  8. #Give the File name of the CSC
  9. $filename = "FileName.csv";
  10. $ListItemCollection = @()
  11. $SPWebApp = Get - SPWebApplication $webApp
  12. # iterating all the sites in the Web Application
  13. foreach($SPSite in $SPWebApp.Sites) {
  14. if ($SPSite - ne $null) {
  15. foreach($SPWeb in $SPSite.AllWebs) {
  16. $WebSize = GetFolderSize($SPWeb.RootFolder)
  17. # Calling the function to calculate Folder Size
  18. # Get Recycle Bin Size
  19. foreach($RecycleBinItem in $SPWeb.RecycleBin) {
  20. $WebSize += $RecycleBinItem.Size
  21. }
  22. #To get the Sub Site Size in MB
  23. $subSiteSize = [Math]::Round($websize / 1 MB, 2)
  24. # To get site owners in the associated owners group
  25. $siteOwners = ""
  26. $siteOwnersGID = ""
  27. foreach($ownerGroup in $SPWeb.AssociatedOwnerGroup) {
  28. foreach($owner in $ownerGroup.Users) {
  29. $siteOwners = $($owner.DisplayName) + "|" + $siteOwners
  30. $siteOwnersGID = $($owner.UserLogin.Split('\')[1]) + "|" + $siteOwnersGID
  31. }
  32. }
  33. #To Get Site Admins
  34. $siteAdmins = ""
  35. foreach($siteAdmin in $SPWeb.SiteAdministrators) {
  36. $siteAdmins = $siteAdmin.LoginName + "|" + $siteAdmins
  37. }#Object for gathering all the required columns
  38. $ExportItem = New - Object PSObject
  39. write - host "DATA"
  40. $SPWeb.Title $siteOwners $siteOwnersGID $siteAdmins $SPWeb.Url $SPWeb.Lists.Count $SPWeb.LastItemModifiedDate $([Math]::Round($SPSite.Usage.Storage / 1 MB, 2)) $subSiteSize
  41. $ExportItem | Add - Member - MemberType NoteProperty - name "Title" - value $SPWeb.Title
  42. $ExportItem | Add - Member - MemberType NoteProperty - name "Site Owner(s)" - value $siteOwners
  43. $ExportItem | Add - Member - MemberType NoteProperty - name "Site Owner(s) GID" - value $siteOwnersGID
  44. $ExportItem | Add - Member - MemberType NoteProperty - name "Site Admin(s)" - value $siteAdmins
  45. $ExportItem | Add - Member - MemberType NoteProperty - name "Site Url" - value $SPWeb.Url
  46. $ExportItem | Add - Member - MemberType NoteProperty - name "List Count" - value $SPWeb.Lists.Count
  47. $ExportItem | Add - Member - MemberType NoteProperty - name "Last Modified Date" - value $SPWeb.LastItemModifiedDate
  48. $ExportItem | Add - Member - MemberType NoteProperty - name "Site Collection Size (MB)" - value $([Math]::Round($SPSite.Usage.Storage / 1 MB, 2))
  49. $ExportItem | Add - Member - MemberType NoteProperty - name "Sub Site Size (MB)" - value $subSiteSize
  50. # Exporting to.CSV File
  51. $ListItemCollection += $ExportItem
  52. $destination = "D:\" + $filename
  53. $ListItemCollection | Export - CSV $destination– NoTypeInformation
  54. }
  55. }
  56. }
  57. #Function to calculate folder size
  58. function GetFolderSize($folder) {
  59. $FolderSize = 0
  60. foreach($File in $Folder.Files) {
  61. #Get File Size
  62. $FolderSize += $file.TotalLength;
  63. #Get the Versions Size
  64. foreach($fileVersion in $file.Versions) {
  65. $FolderSize += $fileVersion.Size
  66. }
  67. }
  68. foreach($subfolder in $folder.SubFolders) {
  69. $FolderSize += GetFolderSize $SubFolder
  70. }
  71. return $FolderSize
  72. }

OutPut ScreenShot

OutPut