Tuesday, 21 April 2009

Win32_Fan Sample using PowerShell

  1. <# 
  2. .SYNOPSIS 
  3.     Uses Win32_Fan class to return information about fans in a system.     
  4. .DESCRIPTION 
  5.     This script first defines some functions to decode various  
  6.     WMI attributed from binary to text. Then the script calls  
  7.     Get-WmiObject to retrieve fan details, then formats that 
  8.     information (using the functions defined at the top of the script. 
  9.      
  10. .NOTES 
  11.     File Name  : Get-Fan.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell V2 CTP3 
  14. .LINK 
  15.     Script posted to: 
  16.     http://pshscripts.blogspot.com/2009/04/win32fan-sample-using-powershell.html
  17.     Original MSDN Page 
  18.     http://msdn.microsoft.com/en-us/library/aa394146(VS.85).aspx 
  19. .EXAMPLE 
  20.     Left as an exercise for the viewer.     
  21. #> 
  22.  
  23. ### 
  24. # Start of Script 
  25. ### 
  26.  
  27. # Functions to decode details 
  28.  
  29. function FanAvailability { 
  30. param ($value) 
  31. switch ($value) { 
  32. 1    {"Other"} 
  33. 2    {"Unknown"} 
  34. 3    {"Running on full power"} 
  35. 4    {"Warning"} 
  36. 5    {"In Test"} 
  37. 6    {"Not Applicable"} 
  38. 7    {"Power Off"} 
  39. 8    {"Off Line"} 
  40. 9    {"Off Duty"} 
  41. 10   {"Degraded"} 
  42. 11   {"Not Installed"} 
  43. 12   {"Install Error"} 
  44. 13   {"Power Save - Unknown"} 
  45. 14   {"Power Save - Low Power Mode"} 
  46. 15   {"Power Save - Standby"} 
  47. 16   {"Power Cycle"} 
  48. 17   {"Power Save - Warning"} 
  49. default {"NOT SET"} 
  50. } 
  51. } 
  52.  
  53. function ConfigManagerErrorCode { 
  54. param ($value) 
  55. switch ($value) { 
  56. 0 {"Device Is Working Properly"} 
  57. 1 {"Device is not configured correctly"} 
  58. 2 {"Windows Cannot load the driver for this device"} 
  59. 3 {"Driver for this device might be corrupted, or the system may be low on memory or other resources"} 
  60. 4 {"Device is not working properly. One of its drivers or the registry might be corrupted"} 
  61. 5 {"Driver for the device requires a resource that Windows cannot manage"} 
  62. 6 {"Boot configuration for the device conflicts with other devices"} 
  63. 7 {"Cannot filter"} 
  64. 8 {"Driver loader for the device is missing"} 
  65. 9 {"Device is not working properly. The controlling firmware is incorrectly reporting the resources for the device"} 
  66. 10 {"Device cannot start"} 
  67. 11 {"Device failed"} 
  68. 12 {"Device cannot fine enough free resources to run"} 
  69. 13 {"Windows cannot verify the devices's resources"} 
  70. 14 {"Device cannot work propertly until the computer is restarted"} 
  71. 15 {"Device is not working properly due to a possible re-enumeration problem"} 
  72. 16 {"Windows cannot identify all of the resources that the device uses"} 
  73. 17 {"Device is requesting an unknown resource type"} 
  74. 18 {"Device drivers must be reinstalled"} 
  75. 19 {"Failure using the VxD loader"} 
  76. 20 {"Registry might be corrupted"} 
  77. 21 {"System failure. if changing the device driver is ineffective, see the hardware documentation. Windows is removing the device"} 
  78. 22 {"Device is disabled"} 
  79. 23 {"System failure. if changing the device driver is ineffective, see the hardware documentation"} 
  80. 24 {"Device is not present, not working properly, or does not have all of its drivers installed"} 
  81. 25 {"Windows is still setting up the device"} 
  82. 26 {"Windows is still setting up the device"}  
  83. 27 {"Device does not have valid log configuration"} 
  84. 28 {"Device drivers are not installed"} 
  85. 29 {"Device is disabled. The device firmware did not provide the required resources"} 
  86. 30 {"Device is using an IRQ resource that another device is using"} 
  87. 31 {"Device is not working properly. Windows cannot load the required device drivers."} 
  88. default {"NOT SET"} 
  89. } 
  90. } 
  91.  
  92. function PowerManagementCapabilities { 
  93. param ($value) 
  94. switch ($value) { 
  95. 0 {"Unknown"} 
  96. 1 {"Not Supported"} 
  97. 2 {"Disabled"} 
  98. 3 {"Enabled"} 
  99. 4 {"Power Saving Modes Entered Automatically"} 
  100. 5 {"Power State Settable"} 
  101. 6 {"Power Cycling Supported"} 
  102. 7 {"Timed Power-On Supported"} 
  103. default {"NOT SET"} 
  104. } 
  105. }  
  106.  
  107. function StatusInfo { 
  108. param ($value) 
  109. switch ($value) { 
  110. 0 {"Other"} 
  111. 2 {"Unknown"} 
  112. 3 {"Enabled"} 
  113. 4 {"Disabled"} 
  114. 5 {"Not Applicable"} 
  115. default {"NOT SET"} 
  116. } 
  117. } 
  118.  
  119. ### 
  120. # Start of Script 
  121. ## 
  122.  
  123. # Get fan information 
  124. $fans = Get-WmiObject -Class Win32_Fan 
  125.  
  126. # Display information 
  127. $hostnm=hostname 
  128. "Fan Information on System: {0} ({1} fans in total" -f $hostnm, $fans.count 
  129. $i=1 
  130. # display details of each fan 
  131. foreach ($fan in $fans) { 
  132. # Display details 
  133. "Fan: {0}"  -f $i 
  134. "Active Cooling                : {0}" -f $fan.ActiveCooling 
  135. "Availability                  : {0}" -f (fanavailability($fan.availability)) 
  136. "Caption                       : {0}" -f $fan.caption 
  137. "Config Manager Error code     : {0}" -f (ConfigManagerErrorCode($fan.ConfigManagerErrorCode)) 
  138. "Config Manager User Config    : {0}" -f $fan.ConfigManagerUserConfig 
  139. "Creation Class Name           : {0}" -f $fan.CreationClassName 
  140. "Description                   : {0}" -f $fan.Description 
  141. "Desired speed                 : {0}" -f $fan.DesiredSpeed 
  142. "Error Cleared                 : {0}" -f $fan.ErrorCleared 
  143. "Error Description             : {0}" -f $fan.ErrorDescription 
  144. "Install Date                  : {0}" -f $fan.InstallDate 
  145. "Last Error code               : {0}" -f $fan.LastErrorCode 
  146. "Name                          : {0}" -f $fan.name 
  147. "PNP Device Id                 : {0}" -f $fan.PNPDeviceID 
  148. "Power Management Capabilities : {0}" -f (PowerManagementCapabilities($fan.PowerManagementCapabilities)) 
  149. "Status                        : {0}" -f $fan.Status 
  150. "Status Information            : {0}" -f (statusinfo($fan.StatusInfo)) 
  151. "System Creation Class Name    : {0}" -f $fan.syu 
  152. "System Name                   : {0}" -f $fan.SystemName 
  153. "Variable Speed                : {0}" -f $fan.VariableSpeed 
  154.  
  155. $i++;"" 
  156. } 
Technorati Tags: ,,

No comments: