Making Objects Read/Write

Whenever you pipe objects through Select-Object, you actually get a copy of the original object. All properties are now readable and writeable, so you can change the object properties in any way you like. This example reads memory information and then replaces the cryptic form factor and memory type ID numbers with clear text values:

$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"

# raw results with cryptic id numbers:
Get-WmiObject Win32_PhysicalMemory |
Select-Object BankLabel, FormFactor, MemoryType
"-" * 40

# clear-text results:
Get-WmiObject Win32_PhysicalMemory |
Select-Object BankLabel, FormFactor, MemoryType |
ForEach-Object {
$_.FormFactor = $formfactor[$_.FormFactor]
$_.MemoryType = $formfactor[$_.MemoryType]
$_
}

Posted Jun 14 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.