PowerShell

PowerShell: Retrieve and store hardware information of domain computers

WMI is a powerful feature. In this article I am going to retrieve information of the installed memory (RAM) of all domain computers and store the output in a file.

The Firewall

In order to run the query, WMI inbound firewall rules must be enabled on all domain computers. This can be done manually or by using Group Policies.

Unbenannt.PNG

Run the WMI Query on all Domain Computers

Then run Get-WmiObject.

Get-WMIObject -ComputerName (Get-ADComputer -Filter *).Name -Class Win32_Computersystem -ErrorAction SilentlyContinue | Select-Object @{n="Computer"; e={$_.PSComputerName}}, @{n="RAM/GB"; e={[Math]::Round($_.TotalPhysicalMemory/ 1GB)}}

Unbenannt.PNG

To make it more user-friendly pipe it to Out-GridView.

 Get-WMIObject -ComputerName (Get-ADComputer -Filter *).Name -Class Win32_Computersystem -ErrorAction SilentlyContinue | Select-Object @{n="Computer"; e={$_.PSComputerName}}, @{n="RAM/GB"; e={[Math]::Round($_.TotalPhysicalMemory/ 1GB)}} | Out-GridView 

Run it on Servers only

It is probably more useful to execute the query for servers only. These are usually always switched on.

Get-WMIObject -ComputerName (Get-ADComputer -Filter 'operatingsystem -like "*server*"').Name -Class Win32_Computersystem -ErrorAction SilentlyContinue | Select-Object @{n="Computer"; e={$_.PSComputerName}}, @{n="RAM/GB"; e={[Math]::Round($_.TotalPhysicalMemory/ 1GB)}} | Out-GridView

Or save it as HTML file.

Get-WMIObject -ComputerName (Get-ADComputer -Filter 'operatingsystem -like "*server*"').Name -Class Win32_Computersystem -ErrorAction SilentlyContinue | Select-Object @{n="Computer"; e={$_.PSComputerName}}, @{n="RAM/GB"; e={[Math]::Round($_.TotalPhysicalMemory/ 1GB)}} | ConvertTo-Html -Title "RAM all Servers" | Set-Content C:\temp\RAM.htm

Unbenannt.PNG

Conclusion

WMI queries can only retrieve information from powered on computers. SCCM uses Client Agents which report hardware and software inventory to the management server in a pre-configured time cycle. More about SCCM here: https://www.microsoft.com/en-us/cloud-platform/system-center-configuration-manager

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.