Discussion:
[MSh] How do i check for battery status of Wireless Mouse
(too old to reply)
DontBotherMeWithSpam
2005-11-23 18:07:21 UTC
Permalink
I am wondering if it is possible to check battery status of microsoft
wireless mouse through MSH.

Or do i have to resort to using WMI object to be able to get status of
it?
James Truher [MSFT]
2005-11-24 21:00:34 UTC
Permalink
I think that get-wmiobject is probably your best bet

jim
--
James W. Truher [MSFT]
Monad Program Management
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by DontBotherMeWithSpam
I am wondering if it is possible to check battery status of microsoft
wireless mouse through MSH.
Or do i have to resort to using WMI object to be able to get status of
it?
DontBotherMeWithSpam
2005-11-25 00:44:16 UTC
Permalink
I have been trying to get battery status through

MSH> $mouse = get-wmiobject Win32_PointingDevice

But since I am lacking WMI knowledge, I am having hard time trying to
do a simple "select * from Win32_Battery where deviceID =
$mouse.deviceID" query. Bah, back to the basic... :)
Adam Barr [MSFT]
2005-12-01 18:22:59 UTC
Permalink
You can do the filtering within the WMI query:

MSH> get-wmiobject Win32_Battery -filter "DeviceId = '$($mouse.DeviceId)'"

[For reasons I'm not quite sure of, get-wmiobject is failing unless you
surround the DeviceId string with single quotes in the filter.]

You can also do the filtering outside of the WMI query using Monad:

MSH> get-wmiobject Win32_Battery | where-object { $_.DeviceId -eq
$mouse.DeviceId }


I wrote a blog post about more advanced queries with get-wmiobject:

http://www.proudlyserving.com/archives/2005/08/monad_and_wmi.html

Thanks.

- adam


Adam Barr [MSFT]
Monad Program Management
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by DontBotherMeWithSpam
I have been trying to get battery status through
MSH> $mouse = get-wmiobject Win32_PointingDevice
But since I am lacking WMI knowledge, I am having hard time trying to
do a simple "select * from Win32_Battery where deviceID =
$mouse.deviceID" query. Bah, back to the basic... :)
DontBotherMeWithSpam
2005-12-01 20:02:13 UTC
Permalink
Thank you for your help. But I guess there are no battery object
present in WMI for that mouse device I have. Anyways, it was fun stuff
to try out. ;)

Oh yeah, I have enjoyed those WMI and Msh tips on your site. :)

bTW, below is the transcript i have recorded according to your tip.

**********************
MSH Transcript Start
Start time: 20051201143901

Transcript started, output file is ./mouseBattery.txt
MSH>$mouse = get-WmiObject Win32_PointingDevice
MSH>$mouse | gm -MemberType properties


TypeName:
System.Management.ManagementObject#root\cimv2\Win32_PointingDevice

Name MemberType Definition

---- ---------- ----------

...
SystemName Property System.String SystemName {get;}



MSH>$battery = get-wmiobject Win32_Battery | where-object { $_.DeviceId
-eq
Post by Adam Barr [MSFT]
$mouse.DeviceId }
MSH>$battery | gm
get-member : No object has been specified to get-member.
At line:1 char:13
+ $battery | gm <<<<
MSH>$battery = get-wmiobject Win32_Battery -filter "DeviceId =
'$($mouse.DeviceId)'"
get-WMIObject : Invalid query
At line:1 char:25
+ $battery = get-wmiobject <<<< Win32_Battery -filter "DeviceId =
'$($mouse.DeviceId)'"
MSH>stop-transcript
**********************
MSH Transcript End
End time: 20051201144147
**********************
Adam Barr [MSFT]
2005-12-01 21:20:18 UTC
Permalink
You may indeed have no matching battery objects. But from the errors, I
would check if $mouse is a scalar or an array. You shouldn't be getting the
"Invalid query" error from get-wmiobject...but if $mouse is an array then
you would because $mouse.DeviceId would be invalid (and get-member hides the
difference between scalar and array).

Although I don't think it would fail quite like that...anyway make sure that
$mouse.DeviceId is what you expect it to be.

- adam

Adam Barr [MSFT]
Monad Program Management
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by DontBotherMeWithSpam
Thank you for your help. But I guess there are no battery object
present in WMI for that mouse device I have. Anyways, it was fun stuff
to try out. ;)
Oh yeah, I have enjoyed those WMI and Msh tips on your site. :)
bTW, below is the transcript i have recorded according to your tip.
**********************
MSH Transcript Start
Start time: 20051201143901
Transcript started, output file is ./mouseBattery.txt
MSH>$mouse = get-WmiObject Win32_PointingDevice
MSH>$mouse | gm -MemberType properties
System.Management.ManagementObject#root\cimv2\Win32_PointingDevice
Name MemberType Definition
---- ---------- ----------
...
SystemName Property System.String SystemName {get;}
MSH>$battery = get-wmiobject Win32_Battery | where-object { $_.DeviceId
-eq
Post by Adam Barr [MSFT]
$mouse.DeviceId }
MSH>$battery | gm
get-member : No object has been specified to get-member.
At line:1 char:13
+ $battery | gm <<<<
MSH>$battery = get-wmiobject Win32_Battery -filter "DeviceId =
'$($mouse.DeviceId)'"
get-WMIObject : Invalid query
At line:1 char:25
+ $battery = get-wmiobject <<<< Win32_Battery -filter "DeviceId =
'$($mouse.DeviceId)'"
MSH>stop-transcript
**********************
MSH Transcript End
End time: 20051201144147
**********************
DontBotherMeWithSpam
2005-12-03 21:09:32 UTC
Permalink
I have checked if $mouse is of scalar or of an array type. It turned
out to be a scalar object.
I think the problem was that "$bat = get-wmiobject Win32_Battery" does
not create any object as following transcript shows

**********************
MSH Transcript Start
Start time: 20051203161001
**********************
Transcript started, output file is mouseBattery2.txt
MSH>$bat = Get-WmiObject Win32_Battery
MSH>$bat
MSH>$bat | gm
get-member : No object has been specified to get-member.
At line:1 char:9
+ $bat | gm <<<<
MSH>stop-transcript
**********************
MSH Transcript End
End time: 20051203161023
**********************

Since Win32_Battery can't even be created without having to filter, I
think it's because Win32_Battery doesn't contain any information IMHO.
/\\/\\o\\/\\/
2005-12-01 21:18:58 UTC
Permalink
Post by DontBotherMeWithSpam
Thank you for your help. But I guess there are no battery object
present in WMI for that mouse device I have. Anyways, it was fun stuff
to try out. ;)
Oh yeah, I have enjoyed those WMI and Msh tips on your site. :)
you can filter in the WMI query also.
you can just do this

MSH>get-WmiObject Win32_PointingDevice

to see if its filled in (it will list all, but don't know how many
mouses you got but I can live with that (PS you see the ID then in the
output ;-)

then you need to "escape" the \'s in the filter (the WMI "escape")

so this works (change to your ID) :

get-wmiobject win32_pointingdevice -filter "PNPDeviceID =
'ACPI\\PNP0F13\\4&5ADF620&0'"

then you can check the Availability property :

win32_pointingdevice Properties :

Availability :
The availability and status of the device. For example, the
Availability property indicates that the device is running and has full
power
(value=3), or is in a warning (4), test (5), degraded (10) or power save
state (values 13-15 and 17). Regarding the power saving states, th
ese are defined as follows: Value 13 ("Power Save - Unknown") indicates
that the device is known to be in a power save mode, but its exact
status in this mode is unknown; 14 ("Power Save - Low Power Mode")
indicates that the device is in a power save state but still functioning
, and may exhibit degraded performance; 15 ("Power Save - Standby")
describes that the device is not functioning but could be brought to fu
ll power 'quickly'; and value 17 ("Power Save - Warning") indicates that
the device is in a warning state, though also in a power save mode

PS with my Logitec Wireless Optical it was Null ;-(

gr /\/\o\/\/

PS info came from

http://mow001.blogspot.com/2005/11/wmi-help-part-2.html

PS2 if you have the status also check this method :

SetPowerState :
SetPowerState defines the desired power state for a logical device and
when a device should be put into that state. The desired power state
is specified by setting the PowerState parameter to one of the
following integer values: 1="Full Power", 2="Power Save - Low Power Mode",
3="Power Save - Standby", 4="Power Save - Other", 5="Power Cycle" or
6="Power Off". The Time parameter (for all state changes, except 5, "P
ower Cycle") indicates when the power state should be set, either as a
regular date-time value or as an interval value (where the interval
begins when the method invocation is received). When the PowerState
parameter is equal to 5, "Power Cycle", the Time parameter indicates wh
en the device should power on again. Power off is immediate.
SetPowerState should return 0 if successful, 1 if the specified
PowerState and
Time request is not supported, and some other value if any other error
occurred. In a subclass, the set of possible return codes could be
specified, using a ValueMap qualifier on the method. The strings to
which the ValueMap contents are 'translated' may also be specified in t
he subclass as a Values array qualifier.
DontBotherMeWithSpam
2005-12-03 21:23:02 UTC
Permalink
Post by /\\/\\o\\/\\/
PS with my Logitec Wireless Optical it was Null ;-(
Ah, Availability came out as Null in my case as well.
I guess there isn't anything else for me to do for now...
Thanks for the help.

Continue reading on narkive:
Loading...