This blog will present you a way to retrieve Windows Server main information via PowerShell. The goal is to be able to automate the extraction of information for different purposes: audit, report generation, dashboards…
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!
Computer System information
First, I initialize the WMI object containing the computer system information of my Windows Server:
This object contains a lot of information regarding your computer system. If you want to know all the information you can obtain from this object, proceed as follows:
Here is an example of the information which can be retrieved:
The Total Physical Memory is displayed in Bytes.
Operating System Information
First, I initialize the WMI object containing the operating system information of my Windows Server:
As for the Computer System information, you can list all the information contained in the WMI object with:
Here is an example of the information which can be retrieved:
The Free Physical Memory is displayed in Kilobytes.
The Install Date property is not very intuitive by default! You need to format the value, as follows:
The date is displayed depending on the culture. In this example, the culture is set to “fr-CH”, so the date is displayed in French.
The OS Language is not very intuitive. The value 1033 correspond to “en-US”. It can be formatted through PowerShell, as follows:
By formatting the information you retrieve in the instance SMO object, you can generate reports, audit your environment or whatever!
The following capture is an existing dashboard from our Database Management Kit (DMK).
Next Steps
In almost all cases, you can do the same thing in T-SQL through the “sqlcmd” command. Indeed, the Windows Sever information are accessible directly in SQL Server via the DMV’s beginning with “sys.dm_os”.
Here is an example:
I hope this blog will help you in your work!