Created
July 11, 2021 03:02
-
-
Save sakkke/bdfc920da76eee211195754c64642bea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://superuser.com/a/532109 | |
param([switch]$Elevated) | |
function Test-Admin { | |
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) | |
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
} | |
if ((Test-Admin) -eq $false) { | |
if ($elevated) { | |
# tried to elevate, did not work, aborting | |
} else { | |
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) | |
} | |
exit | |
} | |
# instance id of pnp device to toggle | |
$instanceId = '' | |
function Toggle-PnpDevice { | |
param( | |
[parameter(ValueFromPipeline)] $pnpDevice | |
) | |
if ($pnpDevice.Status -eq 'OK') { | |
$pnpDevice | Disable-PnpDevice -Confirm:$false | |
} else { | |
$pnpDevice | Enable-PnpDevice -Confirm:$false | |
} | |
} | |
Get-PnpDevice | ? { $_.InstanceId -eq $instanceId } | Toggle-PnpDevice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment