views:

191

answers:

2

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
+1  A: 

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.)

Joey
A: 

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.

OldFart
Is the second call to gwmi actually necessary? Shouldn't the first one contain the info already?
Joey
Maybe it is there, but I looked for it and didn't find it.
OldFart