Retrieve Inventory Information via WMI


posted by Tobias Weltner
11-24-2008

Downloads: 724
File size: 574 B
Views: 4,127

Embed
Retrieve Inventory Information via WMI
  1. function Get-ComputerInfo
  2.     param($computer = "."
  3.  
  4.     # create a result variable with the two new properties MODEL and MEMORY: 
  5.     # (add more properties if you want more information) 
  6.     $result = "" | Select-Object Model,Memory 
  7.  
  8.     # fill information into the result variable: 
  9.     # (add more WMI queries to add more information) 
  10.     $result.Model = (Get-WmiObject win32_bios -computerName $computer).Manufacturer 
  11.     $result.Memory = (Get-WmiObject win32_operatingsystem -computerName $computer).TotalVisibleMemorySize 
  12.  
  13.     # return the result: 
  14.     $result 
  15.  
  16. Get-ComputerInfo 
demonstrates how you can retrieve pieces of computer information like model and memory and combine them in one new self-defined object variable. Based on this sample, you can expand inventory and include as many self-defined properties and fill them with as many pieces of information you want. Since all results are returned as one object, you can then export the object to XML, write it to disk, save it as CSV or do whatever else you want - the usual PowerShell object pipeline commands work with your resiult object just fine.
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.