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
 }
}

1 comment:

  1. 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