-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceToggle.ps1
34 lines (31 loc) · 1.21 KB
/
DeviceToggle.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs;
exit;
}
# You can find this in device manager: select the device, right click properties, go to details, then choose "Device instance path"
$deviceId = 'HID\ELAN2514&COL01\5&330385BB&0&0000';
$device = Get-PnpDevice -InstanceId $deviceId -ErrorAction SilentlyContinue;
if ($device) {
switch ($device.Status) {
'OK' {
Write-Host "Disabling device";
pnputil /disable-device $deviceId;
break;
}
default {
Write-Host "Enabling device";
pnputil /enable-device $deviceId;
}
}
<#
# Comment the switch and uncomment the following to make this a restarter instead of a switch
Write-Host "Restarting device";
pnputil /disable-device $deviceId;
Start-Sleep -Seconds 1;
pnputil /enable-device $deviceId;
#>
}
else {
Write-Warning "Device with ID '$deviceId' not found";
Start-Sleep -Seconds 10;
}