我有一台非常慢且相对便宜的计算机。当我打开它时,我打开了我的蓝牙鼠标。鼠标正常工作几秒钟,然后连接断开。如果我然后重新连接鼠标,它会正常工作,直到我再次将其关闭。
我的目标是:我想编写一个 PowerShell 脚本来自动重新连接鼠标,但我不知道它在 PowerShell 中如何与蓝牙配合使用。有人可以帮我吗?
几天前我问了这个问题, 如何在 windows powerhell 中连接和删除蓝牙,但是每当我尝试运行代码时:
$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
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Run Code Online (Sandbox Code Playgroud)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
我正在使用提升的权限运行它,并且没有错误代码enable-pnpdevice,只有 disable-pnpdevice 有问题。
有谁知道如何做到这一点?在 paul 发表评论后,我再次检查我是否是管理员,我不是,但是当我这样做时,现在会弹出:
Disable-PnpDevice : 不支持 At line:2 char:1 + Disable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false …