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.
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)}}
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
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
Categories: PowerShell, Windows Server