Search This Blog

Thursday, January 16, 2014

How to get the List of all databases in SharePoint 2010 using Powershell

To retrieve a list of SharePoint databases.  When you run Get-SPDatabase, you are provided the Name, Id, and Type of SharePoint databases.

PS C:\> Get-SPDatabase

If you run Get-SPDatabase | Select Name, only the database name is brought in entirety.

PS C:\> Get-SPDatabase | Select Name

If you want to save the output to a file. Then use Out-File parameter. Like that :

PS C:\>Get-SPDatabase | Sort-Object Name | Select Name | Out-File C:\SharePointDBList.txt



The below script builds a script that returns all the databases where the name doesn’t match the name from the SharePoint databases.

$file = New-Item -type file "C:\SPDBs.txt" -force
add-content $file "select name from sys.databases where name not in ("
Get-SPDatabase | foreach-object{add-content $file $_.Name}
add-content $file ")"
ii $file

No comments:

Post a Comment