Thursday, March 28, 2019

Get all web applications and its databases using PowerShell script

Environment: SharePoint 2010/2013

Requirement: To get the list of all WebApplication, Site Collection and its Content databases details

Solution:

Using PowerShell Script

$Today = [string]::Format( "{0:dd-MM-yyyy}", [datetime]::Now.Date ) 
$TranscriptFileName = "C:\\iLink\\AllWeb_ContentDB_$Today.txt" 
Start-Transcript -path $TranscriptFileName
 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null 
$OFS = "`r`n" 
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local 
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]} 
$webapps = @() 

 
 
foreach ($websvc in $websvcs) { 
        #loop through each webapplication 
  foreach ($webapp in $websvc.WebApplications) { 
  #loop through each site collection 
$sites=get-spsite -limit all -WebApplication $webapp.URL 

    foreach ($site in $webapp.Sites) { 
          $ContentDB = Get-SPContentDatabase -site $site.url 
$webappurl = $webapp.URL; 
  Write-Host "Web Application URL:" $webappurl ""$OFS 
$webappname=$webapp.DisplayName 
 
               Write-Host "Web Application Name" -value $webappname  ""$OFS 
               Write-Host "Site URL" -value $site.url     ""$OFS 
               Write-Host "Database Name" -value $ContentDB.Name   ""$OFS 
               Write-Host "Database Size" -value $($ContentDB.DiskSizeRequired /1024/1024)  ""$OFS 
               Write-Host "Date Created" -value $site.RootWeb.Created    ""$OFS 
               Write-Host "OWner" -value $site.Owner        ""$OFS  ""$OFS   ""$OFS 
       } 
      write-host ""$OFS 
     } 
      write-host ""$OFS 

write-host "Request Completed"  ""$OFS
 
Stop-Transcript


No comments:

Post a Comment