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. } 
  70.  
  71. function Handedness { 
  72. param ($value) 
  73. switch ($value) { 
  74. 0 {"Unknown"} 
  75. 1 {"Not Applicable"} 
  76. 2 {"Right-Handed Operation"} 
  77. 3 {"Left-Handed Operation"} 
  78. } 
  79. } 
  80.  
  81. function Pointingtype { 
  82. param ($value) 
  83. switch ($value) { 
  84. 1 {"Other"} 
  85. 2 {"Unknown"} 
  86. 3 {"Mouse"} 
  87. 4 {"Track Ball"} 
  88. 5 {"Track Point"} 
  89. 6 {"Glide Point"} 
  90. 7 {"Touch Pad"} 
  91. 8 {"Touch Screen"} 
  92. 9 {"Mouse - Optical Sensor"} 
  93. } 
  94. } 
  95.  
  96. # Now do script stuff 
  97. # Get Mouse information 
  98. $mice = Get-WmiObject -Class Win32_PointingDevice 
  99. $i=1 
  100.  
  101. foreach ($mouse in $mice) { 
  102.  
  103. # Display details 
  104. "Mouse Information on System: {0} (device {1})" -f $mouse.systemname, $i 
  105. "Description            : {0}" -f $mouse.Description 
  106. "Device ID              : {0}" -f $mouse.DeviceID 
  107. "Device Interface       : {0}" -f (Deviceinterface($mouse.DeviceInterface)) 
  108. "Double Speed Threshold : {0}" -f $mouse.DoubleSpeedThreshold 
  109. "Handedness             : {0}" -f (Handedness($mouse.handedness)) 
  110. "Hardware Type          : {0}" -f $mouse.Hardwaretype 
  111. "INF File Name          : {0}" -f $mouse.InfFileName 
  112. "Inf Section            : {0}" -f $mouse.InfSection 
  113. "Manufacturer           : {0}" -f $mouse.Manufacturer 
  114. "Name                   : {0}" -f $mouse.Name 
  115. "Number of buttons      : {0}" -f $mouse.NumberOfButtons 
  116. "PNP Device ID          : {0}" -f $mouse.PNPDeviceID 
  117. "Pointing Type          : {0}" -f (Pointingtype ($mouse.PointingType)) 
  118. "Quad Speed Threshold   : {0}" -f $mouse.QuadSpeedThreshold 
  119. "Resolution             : {0}" -f $mouse.Resolution 
  120. "Sample Rate            : {0}" -f $mouse.SampleRate 
  121. "Synch                  : {0}" -f $mouse.Synch 
  122. $i++ 
  123. } 
  124. # End of Script 

No comments: