如何使这个If-Else工作

时间:2017-05-02 07:42:34

标签: powershell

我正在使用我的设备“集成网络摄像头”创建PowerShell脚本模板。工作中存在一个问题,当屏幕关闭时,触摸屏正在启用。

我一直在尝试创建所述脚本,使其在运行脚本时不会执行此操作,并决定通过PowerShell启用或禁用触摸屏设备。

因此带我到这里,有什么建议吗?

(原谅笔记,只记录自己)

REM Get-WmiObject Win32_PNPEntity | where {$_.name -like "Integrated Webcam*"}

Import-module .\DeviceManagement.psd1

REM Get-Device | where {$_.name -like "Integrated Webcam*"} | Disable-Device
REM Get-Device | where {$_.name -like "Integrated Webcam*"} | Enable-Device

REM Get-Device | where {$_.name -like "Integrated Webcam*"}
REM ***ConfigurationFlags  : CONFIGFLAG_DISABLED ---> Disabled
REM ***ConfigurationFlags  : 0           ---> Enabled

REM Variables
$OnStatus = Get-WmiObject Win32_PNPEntity | where {$_.Status -eq "OK"}
$OffStatus = Get-WmiObject Win32_PNPEntity | where {$_.Status -eq "Error"}
$DeviceID = Get-WmiObject Win32_PNPEntity | where {$_.DeviceID -like "USB\VID_0C45&PID_64AD&MI_00\7&342EE79C&0&0000"}


REM Get-WmiObject Win32_PNPEntity | where {$_.Status -like "Error*"}

REM Get-Device ???? 
REM **Disable Device -- Works**
if 
($DeviceID -AND $OnStatus){
Get-Device | where {$_.name -like "Integrated Webcam*"} | Disable-Device
REM  **Else doesn't work** **Tried elseif also**
}else{
 Get-Device | where {$_.name -like "Integrated Webcam*"} | Enable-Device 
}

REM **Enable device -- works ** 
if ($DeviceID -AND $OffStatus){
 Get-Device | where {$_.name -like "Integrated Webcam*"} | Enable-Device 
}

0 个答案:

没有答案