Advertisement
St1cky

DISABLING_POWERSAVING_USB

Mar 9th, 2021
1,230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ErrorActionPreference= 'silentlycontinue'
  2. if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))  
  3. {  
  4.   $arguments = "& '" +$myinvocation.mycommand.definition + "'"
  5.   Start-Process powershell -Verb runAs -ArgumentList $arguments
  6.   Break
  7. }
  8.  
  9. Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
  10.  
  11. $devicesUSB = Get-PnpDevice | where {$_.InstanceId -like "*USB\ROOT*"}  |
  12. ForEach-Object -Process {
  13. Get-CimInstance -ClassName MSPower_DeviceEnable -Namespace root\wmi
  14. }
  15.  
  16. foreach ( $device in $devicesUSB )
  17. {
  18.     Set-CimInstance -Namespace root\wmi -Query "SELECT * FROM MSPower_DeviceEnable WHERE InstanceName LIKE '%$($device.PNPDeviceID)%'" -Property @{Enable=$False} -PassThru
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement