首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell禁用Windows 7上的蓝牙

PowerShell禁用Windows 7上的蓝牙
EN

Stack Overflow用户
提问于 2016-07-19 07:58:46
回答 1查看 2.1K关注 0票数 0

我正在通过SCCM创建一个Windows 7映像,并希望通过任务序列禁用蓝牙,到目前为止我有以下内容。我收到了一个关于路径的错误,因为它中有空格,我认为这是由于$ScriptPath。我能帮上忙吗,干杯。

代码语言:javascript
复制
$ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$BTDisabled = $False

$id = Get-CimInstance Win32_PnPEntity | where caption -like 'Intel(R) Wireless Bluetooth(R)'
$id = $id.DeviceID
$ppid = "{0}{1}" -f '@',$id 
Write-host "This is the PPID...  "
Write-Host $PPID
$devcon = $ScriptPath + "\devcon64.exe"
Write-Host "Going to invoke expression..."

$PIDStatus = Invoke-Expression "$devcon status ""$ppid"""

Write-Host "Invoked Expression completed..."
Write-Host $PIDStatus

if ($PIDStatus -like '*disabled*') {$BTDisabled = $True}
Write-Host -ForegroundColor Yellow "Bluetooth is disabled : " $BTDisabled
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-19 09:35:27

尝试使用下面的代码,其中我更新了第12行以处理引号:

代码语言:javascript
复制
$ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$BTDisabled = $False

$id = Get-CimInstance Win32_PnPEntity | where caption -like 'Intel(R) Wireless Bluetooth(R)'
$id = $id.DeviceID
$ppid = "{0}{1}" -f '@',$id 
Write-host "This is the PPID...  "
Write-Host $PPID
$devcon = $ScriptPath + "\devcon64.exe"
Write-Host "Going to invoke expression..."

$PIDStatus = Invoke-Expression "& '$devcon' status `"$ppid`""

Write-Host "Invoked Expression completed..."
Write-Host $PIDStatus

if ($PIDStatus -like '*disabled*') {$BTDisabled = $True}
Write-Host -ForegroundColor Yellow "Bluetooth is disabled : " $BTDisabled
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38452626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档