Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, November 21, 2017 1:19 PM
Hello ,
I have many site collections and sub site so please let me know the way to get the size of each site collection and sub site
any powershell or csom utility will be okay.
Thanks
sudhanshu
sudhanshu sharma Do good and cast it into river :)
All replies (4)
Tuesday, November 21, 2017 4:17 PM ✅Answered | 1 vote
Hi
You could refer to the below powershell script link:
http://get-spscripts.com/2010/08/check-size-of-sharepoint-2010-sites.html
Wednesday, November 22, 2017 3:12 AM ✅Answered
Hi,
Please use this code snippet to find all the Site Collection and it's size. To verify this open any of the site collection in SPD and see the size from the right hand side panel.
Uri uriNew = new Uri("http://MyServer");
SPWebApplication oWebApp = SPWebApplication.Lookup(uriNew);
SPSiteCollection collSiteCollection = oWebApp.Sites;
foreach (SPSite oSiteCollection in collSiteCollection)
{
SPSite.UsageInfo oUsageInfo = oSiteCollection.Usage;
long lngStorageUsed = oUsageInfo.Storage;
Response.Write("Site Collection URL: " + oSiteCollection.Url +
" Storage: " + lngStorageUsed.ToString() + "<BR>");
oSiteCollection.Dispose();
}
Murugesa Pandian MCSA,MCSE,MCPD
Please remember to mark the replies as answers or helpful if they really helped and saved your time.
Thursday, November 23, 2017 1:49 AM ✅Answered | 1 vote
Hi,
Here is a code snippet for your reference:
static void Main(string[] args)
{
long siteCollectionSize = 0;
string baseUrl = "http://hp";
Console.WriteLine("Base Url: " + baseUrl + " (Change baseUrl to list sites starting with)");
using (SPSite mainSite = new SPSite(baseUrl))
{
foreach (SPWeb web in mainSite.AllWebs)
{
long webSize = GetSPFolderSize(web.RootFolder) + web.RecycleBin.Cast<SPRecycleBinItem>().Sum(r => r.Size);
if (web.Url.StartsWith(baseUrl))
{
Console.WriteLine(string.Format("({0} {1}", web.Url, FormatSize(webSize)));
siteCollectionSize += webSize;
}
}
}
Console.WriteLine("Total Size: " + FormatSize(siteCollectionSize));
Console.ReadKey(false);
}
public static long GetSPFolderSize(SPFolder folder)
{
long folderSize = 0;
foreach (SPFile file in folder.Files)
folderSize += file.TotalLength
+ file.Versions.Cast<SPFileVersion>().Sum(f => f.Size);
folderSize += folder.SubFolders.Cast<SPFolder>().Sum(sf => GetSPFolderSize(sf));
return folderSize;
}
public static string FormatSize(long size)
{
if (size > Math.Pow(1024, 3))
return (size / Math.Pow(1024, 3)).ToString("#,#.##") + " GB";
else if (size > Math.Pow(1024, 2))
return (size / Math.Pow(1024, 2)).ToString("#,#.##") + " MB";
else if (size > 1024)
return (size / 1024).ToString("#,#.##") + " KB";
else
return size.ToString("#,#.##") + " Bytes";
}
More information:
Thanks
Best Regards
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]
Thursday, November 23, 2017 5:15 AM ✅Answered
HI Thanks All.
This information also can be verified OOTB.
Site Settings->Site Collection Administrator-> Storage Metrics.
Regards,
Sudhanshu
sudhanshu sharma Do good and cast it into river :)