4

I asked this question a few days ago, How to connect and remove bluetooth in windows powerhell, but whenever I try running the code:

$device = Get-PnpDevice | Where-Object {$_.Class -eq "Bluetooth" -and $_.FriendlyName -eq "MX Master 2S"}
Disable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false
Start-Sleep -Seconds 10
Enable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false

I get this error:

Disable-PnpDevice : Generic failure 
At C:\Users\wadeb\OneDrive\Desktop\Mouse Bluetooth Reset.ps1:2 char:1
+ Disable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Win32_PnPEntity...B17A1&0&FAD...):ROOT\cimv2\Win32_PnPEntity) [ 
   Disable-PnpDevice], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041001,Disable-PnpDevice

I am running it with elevated permissions, and there is no error code with enable-pnpdevice, there are only problems with disable-pnpdevice.

Does anyone know how to do this? after paul's comment, I double checked if I was in administrator, I wasn't, but when I did, this now pops up:

Disable-PnpDevice : Not supported At line:2 char:1 + Disable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotImplemented: (Win32_PnPEntity...B17A1&0&FAD...):ROOT\cimv2\Win32_PnPEntity) [Disable-PnpDevice], CimException + FullyQualifiedErrorId : HRESULT 0x8004100c,Disable-PnpDevice

also, I ran

$device

Status     Class           FriendlyName                                                                     InstanceId     
------     -----           ------------                                                                     ----------     
OK         Bluetooth       MX Master 2S                                                                     BTHLE\DEV_FA...

Not sure if that is what paul meant by contained though.
After a while, with Paul helping me in the chat, we determined that there was a problem with my Bluetooth chip, or the actual software, so if anyone has any ideas about that, that would be greatly appreciated.

AllAwesome497
  • 190
  • 2
  • 3
  • 14
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/185098/discussion-on-question-by-its-programing-not-coding-powershell-not-allowing-me-t). – Samuel Liew Dec 12 '18 at 01:05

2 Answers2

9

I just experienced the exact same problem and couldn't find a solution online. However, I discovered (by trial and error) that the issue was that the PowerShell script and/or command prompt must be started with "Run As Administrator" privileges. Once I did that, I was able to run the command just fine.

It would be nice if the error message was clear enough to point to that specific issue, but hopefully this will help someone else looking for the solution.

Ampersat
  • 421
  • 3
  • 6
  • I think it was a hardware issue actually, that was a very cheap computer. Wasn't worth the price i paid, but in the end it matters not, i have a decent pc now :). – AllAwesome497 Mar 27 '20 at 20:31
  • I likely have a hardware/driver issue as well (which is what is requiring the stop and start of the device). However, the specific scenario and error message you showed in your question was caused (in my case) by a lack of permissions. I was able to execute the code as long as I ran it as an administrator. This might be true for others as well. – Ampersat Mar 30 '20 at 17:21
  • IIrc i did it with admin perms but i'm certain its a hardware / firmware / bad installation, i have over 500 broken registry items, over 170k junk items etc – AllAwesome497 Mar 30 '20 at 17:45
0
devcon.exe disable "USB\VID_0A12&PID_0001" & devcon.exe enable "USB\VID_0A12&PID_0001"
Zoe
  • 27,060
  • 21
  • 118
  • 148
Serg
  • 9
  • 1
  • 5
    Please add some explanation to your answer – El.Hum Jan 26 '19 at 11:06
  • 2
    Welcome to Where Developers Learn, Share, & Build Careers! While this code snippet may be the solution, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Johan Jan 26 '19 at 13:34
  • For future reference: https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/devcon – Cesar Dec 11 '20 at 07:01