Skip to content

Get the main information from SQL Server databases with PowerShell

As I promised in my previous blog Get the main Administration Information from SQL Server with PowerShell, I will present you this time how to retrieve the SQL Server databases information with PowerShell.
Disclaimer: I am not a developer but a SQL Server dba. If you find errors or some ways of improvement, I will be glad to read your comments!

Retrieve SQL Server databases information

I use the SMO objects to access the instance information. In my previous blog, I explaind how to initialize the SMO object from a specific instance.
Moreover, I also described how to list all installed SQL Server instances on Windows Server.
So, I assume the SMO object from the SQL Server instance has already been initialized, referring to this blog.

To display the main information of your databases, proceed as follows:

databases_main_information.png

You can also obtain the data files information details about your databases. However, be aware that the data files are organized in File Groups. Here is the code which shows how to proceed:

datafiles_information.png

To obtain the log files information, it is a little bit faster. Indeed, log files are not hierarchized in File Groups.

logfiles_information.png

There are some important configuration options in SQL Server for the databases. These options are important to know. I show you how to retrieve them:

database_main_options.png

If you format your output, you can obtain report, dashboards, aso… Here is a capture of an existing dashboard from our Database Management Kit (DMK).

database_dmk.png

Next steps

If you want to learn more about the methods and properties included in the database SMO object, you should use the “Get-Member” command:

smo_object_database_properties_methods.png

I hope this blog will help you. Of course, the SMO object is not the only approach. It can easily be done with the “sqlcmd” command for example.

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Nathan Courtine

Nathan Courtine

Nathan Courtine has more than nine years of experience in Microsoft solutions, specializing in SQL Server installation, migration, performance analysis, and automation. He holds Microsoft Certified Solutions Expert (MCSE), Microsoft Certified Azure Administrator Associate, and AWS Certified Solutions Architect Associate credentials. He holds a Computer Science degree from ENSISA Mulhouse. His industry experience covers the public sector, pharma, IT, and banking/financial services.View Author posts

40 posts since December 2013

Most read in Database

The Database posts our readers open most: the all-time favourites, and what is trending right now.

Leave a Comment

Your email address will not be published. Required fields are marked *