2016-07-19 9 views
0

Ich erstelle ein Windows 7-Image via SCCM und möchte Bluetooth über eine Tasksequenz deaktivieren, bisher habe ich folgendes hier unten. Ich erhalte einen Fehler in Bezug auf den Pfad, da Leerzeichen darin enthalten sind. Ich denke, das liegt an $ ScriptPath. Könnte ich Hilfe dazu bekommen?PowerShell Bluetooth unter Windows 7 deaktivieren

$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 
+0

Haben Sie die 'devcon64.exe' Datei am selben Ort zur Verfügung, wo Ihr Skript ist? – SavindraSingh

+0

Ja, ich mache es, wie funktioniert es, wenn der Pfad Leerzeichen enthält? –

+0

$ devcon = "" "$ ScriptPath \ devcon64.exe" "" – Deptor

Antwort

1

mit folgendem Code Versuchen Sie, wo ich Zeilennummer aktualisiert 12 mit Zitaten zu behandeln:

$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 
+0

Wenn ich den Invoke-Ausdruck Teil verwende bekomme ich "&: Der Begriff 'C: \ PATH \ Pfad 2 \ Scripts \ devcon64.exe' wird nicht als der Name eines Cmdlet erkannt" wenn ich Invoke-Expression heraus nehme läuft es aber tut nichts, wenn ich 'Status' zu 'Deaktivieren' ändere es deaktiviert nicht den Bluetooth-Adapter –

+0

Das war der Grund, fragte ich früher, wenn Sie finden 'devcon64.exe' bei diesem Pfad:' C: \ Pfad \ Pfad 2 \ Scripts \ devcon64.exe' – SavindraSingh

+0

Mein Fehler, Ihr aktuelles Skript hat funktioniert. Ich habe den falschen Namen, die Zitate, die Sie sagen, es half mir Prost. –