Tuesday, 17 August 2010

Get-BrokenHardware.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets a list of non-working hardware using WMI. 
  4. .DESCRIPTION 
  5.     This script re-implements another TechNet Scripting 
  6.     Gallery script that was written in VB (see  
  7.     http://tinyurl.com/y4hmtbr).  
  8.     This script first uses WMI to get system details, then 
  9.     gets and displays hardware that has errored. 
  10. .NOTES 
  11.     File Name  : Get-BrokenHardware.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17.     This script posted to TechNet Script Gallery at: 
  18.         http://gallery.technet.microsoft.com/ScriptCenter/en-us/dbb678f4-b95b-45c3-bc8b-2ae2d052448e     
  19. .EXAMPLE 
  20.     PSH [C:\foo]: Get-BrokenHardware.ps1 
  21.     Computer Details: 
  22.     Manufacturer: Dell Inc. 
  23.     Model:        Precision WorkStation T7400 
  24.     Service Tag:  6Y84C3J 
  25.  
  26.     Hardware that's not working list 
  27.     Description:  WD My Book Device USB Device 
  28.     Device ID:    USBSTOR\OTHER&VEN_WD&PROD_MY_BOOK_DEVICE&REV_1010\7&2A4E07C&0&575532513130303732383932&1 
  29.     Error ID:     28 
  30. #> 
  31.  
  32. # Display Computer details 
  33. "Computer Details:" 
  34. $comp = gwmi Win32_ComputerSystem 
  35. "Manufacturer: {0}" -f $comp.Manufacturer 
  36. "Model:        {0}" -f $comp.Model 
  37. $computer2 = Get-WmiObject Win32_ComputerSystemProduct 
  38. "Service Tag:  {0}" -f $computer2.IdentifyingNumber 
  39. "" 
  40.  
  41. #Get hardware that is errored 
  42. "Hardware that's not working list"  
  43. $broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0} 
  44.  
  45. #Display broken hardware 
  46. foreach ($obj in $broken){   
  47. "Description:  {0}" -f  $obj.Description 
  48. "Device ID:    {0}" -f  $obj.DeviceID 
  49. "Error ID:     {0}" -f  $obj.ConfigManagerErrorCode 
  50. "" 

No comments: