Saturday 3 January 2009

Get-MouseInfo.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Uses Win32_PointingDevice WMI class to return Mouse details.     
  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 Mouse details, then formats that 
  8.     information (using the functions defined at the top of the script. 
  9.      
  10.     While on most systems, there is only one mouse, WMI can return
  11.     multiple devices. Hence the foreach loop. Thanks to Jeffrey
  12.     Snover for the tip-off!  Also note that not all properties
  13.     are returned – although mileage may vary.
  14.      
  15.     This is also sample 7 on http://msdn.microsoft.com/en-us/library/aa394587(VS.85).aspx 
  16.     recoded with PowerShell. 
  17. .NOTES 
  18.     File Name  : Get-Mouseinfo.ps1 
  19.     Author     : Thomas Lee - tfl@psp.co.uk 
  20.     Requires   : PowerShell V2 CTP3 
  21. .LINK 
  22.     Script posted to: 
  23.     http://www.pshscripts.blogspot.com 
  24.     Original MSDN Page 
  25.     http://msdn.microsoft.com/en-us/library/aa394587(VS.85).aspx 
  26. .EXAMPLE 
  27.     PS C:\foo> Get-Mouseinfo.ps1 
  28.     Mouse Information on System: COOKHAM8  (device 1)
  29.     Description            : PS/2 Compatible Mouse 
  30.     Device ID              : ACPI\PNP0F13\4&33DCE2F0&0 
  31.     Device Interface       : PS/2 
  32.     Double Speed Threshold : 
  33.     Handedness             : 
  34.     Hardware Type          : PS/2 Compatible Mouse 
  35.     INF File Name          : msmouse.inf 
  36.     Inf Section            : PS2_Inst 
  37.     Manufacturer           : Microsoft 
  38.     Name                   : PS/2 Compatible Mouse 
  39.     Number of buttons      : 0 
  40.     PNP Device ID          : ACPI\PNP0F13\4&33DCE2F0&0 
  41.     Pointing Type          : Unknown 
  42.     Quad Speed Threshold   : 
  43.     Resolution             : 
  44.     Sample Rate            : 
  45.     Synch                  : 
  46. #> 
  47.  
  48. ### 
  49. # Start of Script 
  50. ### 
  51.  
  52. # Functions to decode details 
  53.  
  54. function Deviceinterface { 
  55. param ($value) 
  56. switch ($value) { 
  57. 0    {"Other"
  58. 1    {"Unknown"
  59. 3    {"Serial"
  60. 4    {"PS/2"
  61. 5    {"Infrared"
  62. 6    {"HP-HIL"
  63. 7    {"Bus Mouse"
  64. 8    {"ADP (Apple Desktop Bus)"
  65. 160  {"Bus Mouse DB-9"
  66. 161  {"Bus Mouse Micro-DIN"
  67. 162  {"USB"
  68.  
  69. function Handedness { 
  70. param ($value) 
  71. switch ($value) { 
  72. 0 {"Unknown"
  73. 1 {"Not Applicable"
  74. 2 {"Right-Handed Operation"
  75. 3 {"Left-Handed Operation"
  76.  
  77. function Pointingtype { 
  78. param ($value) 
  79. switch ($value) { 
  80. 1 {"Other"
  81. 2 {"Unknown"
  82. 3 {"Mouse"
  83. 4 {"Track Ball"
  84. 5 {"Track Point"
  85. 6 {"Glide Point"
  86. 7 {"Touch Pad"
  87. 8 {"Touch Screen"
  88. 9 {"Mouse - Optical Sensor"
  89.  
  90. # Now do script stuff 
  91. # Get Mouse information 
  92. $mice = Get-WmiObject -Class Win32_PointingDevice 
  93. $i=1 
  94.  
  95. foreach ($mouse in $mice) { 
  96.  
  97. # Display details 
  98. "Mouse Information on System: {0} (device {1})" -f $mouse.systemname, $i 
  99. "Description            : {0}" -f $mouse.Description 
  100. "Device ID              : {0}" -f $mouse.DeviceID 
  101. "Device Interface       : {0}" -f (Deviceinterface($mouse.DeviceInterface)) 
  102. "Double Speed Threshold : {0}" -f $mouse.DoubleSpeedThreshold 
  103. "Handedness             : {0}" -f (Handedness($mouse.handedness)) 
  104. "Hardware Type          : {0}" -f $mouse.Hardwaretype 
  105. "INF File Name          : {0}" -f $mouse.InfFileName 
  106. "Inf Section            : {0}" -f $mouse.InfSection 
  107. "Manufacturer           : {0}" -f $mouse.Manufacturer 
  108. "Name                   : {0}" -f $mouse.Name 
  109. "Number of buttons      : {0}" -f $mouse.NumberOfButtons 
  110. "PNP Device ID          : {0}" -f $mouse.PNPDeviceID 
  111. "Pointing Type          : {0}" -f (Pointingtype ($mouse.PointingType)) 
  112. "Quad Speed Threshold   : {0}" -f $mouse.QuadSpeedThreshold 
  113. "Resolution             : {0}" -f $mouse.Resolution 
  114. "Sample Rate            : {0}" -f $mouse.SampleRate 
  115. "Synch                  : {0}" -f $mouse.Synch 
  116. $i++ 
  117. # End of Script 

No comments: