get-wmiobject sql join in powershell - trying to find physical memory vs. virtual memory of remote systems
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 Vi开发者_Python百科rtual Memory
server1 4096mb 8000mb
server2 2048mb 4000mb
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.)
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.
精彩评论