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.
- If((Get - PSSnapIn - Name Microsoft.SharePoint.PowerShell - ErrorAction SilentlyContinue) - eq $null) {
- Add - PSSnapIn - Name Microsoft.SharePoint.PowerShell
- }
- #using the reflection assembly
- [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
- # Give the Web Application Name
- $webApp = 'http://webappname'
- #Give the File name of the CSC
- $filename = "FileName.csv";
- $ListItemCollection = @()
- $SPWebApp = Get - SPWebApplication $webApp
- # iterating all the sites in the Web Application
- foreach($SPSite in $SPWebApp.Sites) {
- if ($SPSite - ne $null) {
- foreach($SPWeb in $SPSite.AllWebs) {
- $WebSize = GetFolderSize($SPWeb.RootFolder)
- # Calling the function to calculate Folder Size
- # Get Recycle Bin Size
- foreach($RecycleBinItem in $SPWeb.RecycleBin) {
- $WebSize += $RecycleBinItem.Size
- }
- #To get the Sub Site Size in MB
- $subSiteSize = [Math]::Round($websize / 1 MB, 2)
- # To get site owners in the associated owners group
- $siteOwners = ""
- $siteOwnersGID = ""
- foreach($ownerGroup in $SPWeb.AssociatedOwnerGroup) {
- foreach($owner in $ownerGroup.Users) {
- $siteOwners = $($owner.DisplayName) + "|" + $siteOwners
- $siteOwnersGID = $($owner.UserLogin.Split('\')[1]) + "|" + $siteOwnersGID
- }
- }
-
- #To Get Site Admins
- $siteAdmins = ""
- foreach($siteAdmin in $SPWeb.SiteAdministrators) {
- $siteAdmins = $siteAdmin.LoginName + "|" + $siteAdmins
- }#Object for gathering all the required columns
- $ExportItem = New - Object PSObject
- write - host "DATA"
- $SPWeb.Title $siteOwners $siteOwnersGID $siteAdmins $SPWeb.Url $SPWeb.Lists.Count $SPWeb.LastItemModifiedDate $([Math]::Round($SPSite.Usage.Storage / 1 MB, 2)) $subSiteSize
- $ExportItem | Add - Member - MemberType NoteProperty - name "Title" - value $SPWeb.Title
- $ExportItem | Add - Member - MemberType NoteProperty - name "Site Owner(s)" - value $siteOwners
- $ExportItem | Add - Member - MemberType NoteProperty - name "Site Owner(s) GID" - value $siteOwnersGID
- $ExportItem | Add - Member - MemberType NoteProperty - name "Site Admin(s)" - value $siteAdmins
- $ExportItem | Add - Member - MemberType NoteProperty - name "Site Url" - value $SPWeb.Url
- $ExportItem | Add - Member - MemberType NoteProperty - name "List Count" - value $SPWeb.Lists.Count
- $ExportItem | Add - Member - MemberType NoteProperty - name "Last Modified Date" - value $SPWeb.LastItemModifiedDate
- $ExportItem | Add - Member - MemberType NoteProperty - name "Site Collection Size (MB)" - value $([Math]::Round($SPSite.Usage.Storage / 1 MB, 2))
- $ExportItem | Add - Member - MemberType NoteProperty - name "Sub Site Size (MB)" - value $subSiteSize
- # Exporting to.CSV File
- $ListItemCollection += $ExportItem
- $destination = "D:\" + $filename
- $ListItemCollection | Export - CSV $destination– NoTypeInformation
- }
- }
- }
- #Function to calculate folder size
-
- function GetFolderSize($folder) {
- $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
- }
- }
- foreach($subfolder in $folder.SubFolders) {
- $FolderSize += GetFolderSize $SubFolder
- }
- return $FolderSize
- }
OutPut ScreenShot