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

查看:28
本文介绍了如何在 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 -class Bluetooth -friendlyname "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天全站免登陆