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. function ConfigManagerErrorCode { 
  52. param ($value
  53. switch ($value) { 
  54. 0 {"Device Is Working Properly"
  55. 1 {"Device is not configured correctly"
  56. 2 {"Windows Cannot load the driver for this device"
  57. 3 {"Driver for this device might be corrupted, or the system may be low on memory or other resources"
  58. 4 {"Device is not working properly. One of its drivers or the registry might be corrupted"
  59. 5 {"Driver for the device requires a resource that Windows cannot manage"
  60. 6 {"Boot configuration for the device conflicts with other devices"
  61. 7 {"Cannot filter"
  62. 8 {"Driver loader for the device is missing"
  63. 9 {"Device is not working properly. The controlling firmware is incorrectly reporting the resources for the device"
  64. 10 {"Device cannot start"
  65. 11 {"Device failed"
  66. 12 {"Device cannot fine enough free resources to run"
  67. 13 {"Windows cannot verify the devices's resources"
  68. 14 {"Device cannot work propertly until the computer is restarted"
  69. 15 {"Device is not working properly due to a possible re-enumeration problem"
  70. 16 {"Windows cannot identify all of the resources that the device uses"
  71. 17 {"Device is requesting an unknown resource type"
  72. 18 {"Device drivers must be reinstalled"
  73. 19 {"Failure using the VxD loader"
  74. 20 {"Registry might be corrupted"
  75. 21 {"System failure. if changing the device driver is ineffective, see the hardware documentation. Windows is removing the device"
  76. 22 {"Device is disabled"
  77. 23 {"System failure. if changing the device driver is ineffective, see the hardware documentation"
  78. 24 {"Device is not present, not working properly, or does not have all of its drivers installed"
  79. 25 {"Windows is still setting up the device"
  80. 26 {"Windows is still setting up the device"}  
  81. 27 {"Device does not have valid log configuration"
  82. 28 {"Device drivers are not installed"
  83. 29 {"Device is disabled. The device firmware did not provide the required resources"
  84. 30 {"Device is using an IRQ resource that another device is using"
  85. 31 {"Device is not working properly. Windows cannot load the required device drivers."
  86. default {"NOT SET"
  87.  
  88. function PowerManagementCapabilities { 
  89. param ($value
  90. switch ($value) { 
  91. 0 {"Unknown"
  92. 1 {"Not Supported"
  93. 2 {"Disabled"
  94. 3 {"Enabled"
  95. 4 {"Power Saving Modes Entered Automatically"
  96. 5 {"Power State Settable"
  97. 6 {"Power Cycling Supported"
  98. 7 {"Timed Power-On Supported"
  99. default {"NOT SET"
  100. }  
  101.  
  102. function StatusInfo { 
  103. param ($value
  104. switch ($value) { 
  105. 0 {"Other"
  106. 2 {"Unknown"
  107. 3 {"Enabled"
  108. 4 {"Disabled"
  109. 5 {"Not Applicable"
  110. default {"NOT SET"
  111.  
  112. ### 
  113. # Start of Script 
  114. ## 
  115.  
  116. # Get fan information 
  117. $fans = Get-WmiObject -Class Win32_Fan 
  118.  
  119. # Display information 
  120. $hostnm=hostname 
  121. "Fan Information on System: {0} ({1} fans in total" -f $hostnm, $fans.count 
  122. $i=1 
  123. # display details of each fan 
  124. foreach ($fan in $fans) { 
  125. # Display details 
  126. "Fan: {0}"  -f $i 
  127. "Active Cooling                : {0}" -f $fan.ActiveCooling 
  128. "Availability                  : {0}" -f (fanavailability($fan.availability)) 
  129. "Caption                       : {0}" -f $fan.caption 
  130. "Config Manager Error code     : {0}" -f (ConfigManagerErrorCode($fan.ConfigManagerErrorCode)) 
  131. "Config Manager User Config    : {0}" -f $fan.ConfigManagerUserConfig 
  132. "Creation Class Name           : {0}" -f $fan.CreationClassName 
  133. "Description                   : {0}" -f $fan.Description 
  134. "Desired speed                 : {0}" -f $fan.DesiredSpeed 
  135. "Error Cleared                 : {0}" -f $fan.ErrorCleared 
  136. "Error Description             : {0}" -f $fan.ErrorDescription 
  137. "Install Date                  : {0}" -f $fan.InstallDate 
  138. "Last Error code               : {0}" -f $fan.LastErrorCode 
  139. "Name                          : {0}" -f $fan.name 
  140. "PNP Device Id                 : {0}" -f $fan.PNPDeviceID 
  141. "Power Management Capabilities : {0}" -f (PowerManagementCapabilities($fan.PowerManagementCapabilities)) 
  142. "Status                        : {0}" -f $fan.Status 
  143. "Status Information            : {0}" -f (statusinfo($fan.StatusInfo)) 
  144. "System Creation Class Name    : {0}" -f $fan.syu 
  145. "System Name                   : {0}" -f $fan.SystemName 
  146. "Variable Speed                : {0}" -f $fan.VariableSpeed 
  147.  
  148. $i++;"" 
Technorati Tags: ,,

No comments: