Power Shell Script to get all site collections 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
}
}
Comments
Post a Comment