Creating a SQL Server database inventory
This recipe walks you through the process of retrieving database properties and saving them to a file for inventorying purposes.
Getting ready
Log in to your SQL Server instance. Check which user databases are available for you to investigate. These same databases should appear in your resulting file after you run the PowerShell script.
How to do it...
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module and create a new SMO Server object, as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "KERRIGAN" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following script and run:
#specify folder and filename to be produced $folder = "C:\Temp" $currdate = Get-Date -Format "yyyy-MM-dd_hmmtt" $filename = "$($instanceName)_DatabaseInventory_$($currdate...