如何在Windows上使用PowerShell脚本连接和断开蓝牙设备? [英] How to connect and disconnect a Bluetooth device with a PowerShell script on Windows?

查看:890
本文介绍了如何在Windows上使用PowerShell脚本连接和断开蓝牙设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台非常慢且相对便宜的计算机.当我打开它时,我会打开我的蓝牙鼠标.鼠标可以正常工作几秒钟,然后断开连接.如果我随后重新连接鼠标,它将一直保持应有的状态,直到再次将其关闭为止.

I have a very slow and relatively cheap computer. When I turn it on, I turn on my Bluetooth mouse. The mouse works fine for a few seconds, then the connection is broken. If I then reconnect the mouse, it works as it should be until I turn it off again.

我的目标是:我想编写一个PowerShell脚本来自动重新连接鼠标,但是我不知道它如何在PowerShell中与蓝牙一起工作.有人可以帮我吗?

My goal is: I would like to write a PowerShell script that will reconnect the mouse automatically, but I don't know how it works with Bluetooth in PowerShell. Could anyone help me with that?

推荐答案

尝试类似的方法,请注意,需要提升的权限:

Try something like this, note that elevated permissions are required:

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

此脚本会禁用设备,并在10秒钟后再次启用它.

This script disables the device and after 10 seconds enables it again.

这篇关于如何在Windows上使用PowerShell脚本连接和断开蓝牙设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆