get-wmiobject sql join in powershell - trying to find physical memory vs. virtual memory of remote systems

StackOverflow https://stackoverflow.com/questions/2816124

  •  26-09-2019
  •  | 
  •  

Question

get-wmiobject -query "Select TotalPhysicalMemory from Win32_LogicalMemoryConfiguration" -computer COMPUTERNAME >>output.csv

get-wmiobject -query "Select TotalPageFileSpace from Win32_LogicalMemoryConfiguration" -computer COMPUTERNAME >>output.csv

I am trying to complete this script with an output as such:

Computer        Physical Memory      Virtual Memory
server1         4096mb               8000mb
server2         2048mb               4000mb
Was it helpful?

Solution

Is anything keeping you from doing something like this?

gwmi -query "Select TotalPhysicalMemory,TotalPageFileSpace from Win32_LogicalMemoryConfiguration" -computer $COMPUTERNAME |
  select @{Name='Computer', Expression=$COMPUTERNAME},
         @{Name='Physical Memory', Expression=$_.TotalPhysicalMemory},
         @{Name='Virtual Memory', Expression=$_.TotalPageFileSize} |
  Export-Csv

(Untested, since Get-WmiOject doesn't know the class Win32_LogicalMemoryConfiguration here. But might work.)

OTHER TIPS

Win32_LogicalMemoryConfiguration appears to be obsolete. I think this function will get the information you want:

function Get-MemoryInfo
{
    Process
    {
        Get-WmiObject Win32_OperatingSystem -ComputerName $_ |
        % {
            New-Object PSObject |
            Add-Member NoteProperty Computer $_.CSName -PassThru |
            Add-Member NoteProperty VirtualMemoryMB ([int]($_.TotalVirtualMemorySize / 1KB)) -PassThru
        } |
        % {
            $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_.Computer
            $_ | Add-Member NoteProperty PhysicalMemoryMB ([int]($cs.TotalPhysicalMemory / 1MB)) -PassThru
        }
    }
}

You can pipe the list of computers into Get-MemoryInfo. Then pipe the output into Export-Csv if you want a csv file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top