Create Remoting Solutions

by Jun 10, 2010

Whenever you use WMI (Get-WMIObject) to retrieve information, it's a snap to turn a local solution into a remotable solution. You can just add the parameter -Computername to Get-WMIObject.

In a previous tip, you learned how to examine physical memory. Here's a wrapper function that makes this code run locally as well as remotely (provided that you have sufficient access privileges):

function Get-Memory($computername = 'localhost') {
$memorytype = "Unknown", "Other", "DRAM", "Synchronous DRAM", "Cache DRAM",
"EDO", "EDRAM", "VRAM", "SRAM", "RAM", "ROM", "Flash", "EEPROM", "FEPROM",
"EPROM", "CDRAM", "3DRAM", "SDRAM", "SGRAM", "RDRAM", "DDR", "DDR-2"
$formfactor = "Unknown", "Other", "SIP", "DIP", "ZIP", "SOJ", "Proprietary",
"SIMM", "DIMM", "TSOP", "PGA", "RIMM", "SODIMM", "SRIMM", "SMD", "SSMP",
"QFP", "TQFP", "SOIC", "LCC", "PLCC", "BGA", "FPBGA", "LGA"
$col1 = @{Name='Size (GB)'={ $_.Capacity/1GB } }
$col2 = @{Name='Form Factor'={$formfactor[$_.FormFactor]} }
$col3 = @{Name='Memory Type'={ $memorytype[$_.MemoryType] } }
$col4 = @{Name='ComputerName'=[Scriptblock]::Create("'$computername'")}
Get-WmiObject Win32_PhysicalMemory -computername $computername |
Select-Object BankLabel, $col1, $col2, $col3, $col4
}

Twitter This Tip! ReTweet this Tip!