#--------------------------------------------------------------------------------------------------------------------------------------------
# Author: Shiv Mangal Singh
# Date: Nov 23, 2015
# Description:
# 1. This script will generate all content databases details(online/ offline/ disabled) across Farm for each Web Application .
# Syntax:
#
# e.g: .\Get_Content_Databases_Across_Farm.ps1
#--------------------------------------------------------------------------------------------------------------------------------------------
# Add SharePoint cmdlets reference
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
try
{
foreach ($websvc in $websvcs)
{
foreach ($webapp in $websvc.WebApplications)
{
write-host $webapp
Write-Host "Testing---Web Application Name:" $webapp.Name
$path = "D:\Contoso_MWTeam\Shiv\PS\db\"+$webapp.Name+"_Webapplication"+".csv"
$csv = "WebApplication,Content Database,DB Status `r`n"
$fso = new-object -comobject scripting.filesystemobject
$file = $fso.CreateTextFile($path,$true)
$file.write($csv)
$webappurl=$webapp.url
foreach($db in $webapp.Contentdatabases)
{
Write-Output $db
$csv =$webappurl + "," +$db.Name+","+$db.Status+"`n";
$file.write($csv)
}
}
}
$file.close()
}
catch [Exception ex]
{
ex.message="exception handling"
}
Write-Host "Work is finished"
# Author: Shiv Mangal Singh
# Date: Nov 23, 2015
# Description:
# 1. This script will generate all content databases details(online/ offline/ disabled) across Farm for each Web Application .
# Syntax:
#
# e.g: .\Get_Content_Databases_Across_Farm.ps1
#--------------------------------------------------------------------------------------------------------------------------------------------
# Add SharePoint cmdlets reference
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
try
{
foreach ($websvc in $websvcs)
{
foreach ($webapp in $websvc.WebApplications)
{
write-host $webapp
Write-Host "Testing---Web Application Name:" $webapp.Name
$path = "D:\Contoso_MWTeam\Shiv\PS\db\"+$webapp.Name+"_Webapplication"+".csv"
$csv = "WebApplication,Content Database,DB Status `r`n"
$fso = new-object -comobject scripting.filesystemobject
$file = $fso.CreateTextFile($path,$true)
$file.write($csv)
$webappurl=$webapp.url
foreach($db in $webapp.Contentdatabases)
{
Write-Output $db
$csv =$webappurl + "," +$db.Name+","+$db.Status+"`n";
$file.write($csv)
}
}
}
$file.close()
}
catch [Exception ex]
{
ex.message="exception handling"
}
Write-Host "Work is finished"
nice blogs about Mastering PowerShell Scripting at The
ReplyDeleteMastering PowerShell Scripting training in bangalore