Thursday, August 22, 2013

PowerShell script to get all site collections details in web application

function GetAllWebApplications()
{
 
 write-host "Sitecollection List Extraction started...." -foregroundcolor yellow
 $contentWebAppServices = (Get-SPFarm).services |
 ? {$_.typename -eq "Microsoft SharePoint Foundation Web Application"}

 foreach($webApp in $contentWebAppServices.WebApplications)
 {
 Write-Host "Web Application : " $webApp.name
 
 #Fetch the site collections from the web application.
 GenerateAllSitecollectionsInWebapplication $webApp.Url 
 } 
}


function GenerateAllSitecollectionsInWebapplication ($url)
{
 
 try
 {
 $Site=Get-SPSite $url -ErrorAction SilentlyContinue
 $spWebApp = $Site.WebApplication
 $TotalList = @()
 $logfilepath = scriptDirectory
  
 foreach($spSite in $spWebApp.Sites)
 {
  $list = $spSite.url
 #write-host $list -foregroundcolor green 
  
 #Code to get the storage used in MB's
 [int]$usage = $spSite.usage.storage/1MB
 
 #Code to get the quota template name
 $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
 $quotaTemplate = $contentService.QuotaTemplates | where {$_.QuotaID -match $spSite.Quota.QuotaID}
 
 #write-host $spSite.RootWeb.Title "|" $spSite.Url "|" $spSite.ContentDatabaseName "|" $usage "|" $spSite.Quota.QuotaID
 $outputString += $spSite.RootWeb.Title
 $outputString += " | "
 $outputString += $spSite.Url
 $outputString += " | "
 $outputString += $spSite.ContentDatabase.Name
 $outputString += " | "
 $outputString += $usage
 $outputString += " | "
 $outputString += $quotaTemplate.Name
 
write-host $logfilepath $outputString
 
 } 
 }
 catch
 {
 write-host "Unable to Extract Sitecollection List..." -foregroundcolor red
 break
 }
}

2 comments:

  1. This is a good article & good site.Thank you for sharing this article. It is help us following categorize:
    healthcare, e commerce, programming, multi platform,inventory management, cloud-based solutions, it consulting, retail, manufacturing, CRM, technology means, digital supply chain management, Delivering high-quality service for your business applications,
    Solutions for all Industries,
    Getting your applications talking is the key to better business processes,
    Rapid web services solutions for real business problems,
    Web-based Corporate Document Management System,
    Outsourcing Solution,
    Financial and Operations Business Intelligence Solution,

    Our address:
    2002 Timberloch Place, Suite 200
    The Woodlands, TX 77380
    281-364-1799

    prologic-corp

    ReplyDelete
  2. Thanks for sharing this wonderful article about Sharepoint with us, Also please tell me that How can you create a Task Notifications workflow in SharePoint? And explain how to manage projects in SharePoint? Thanks again in advance.

    The Funeral Homes Marketing Solutions by OptimiZed360.Com

    ReplyDelete