powershell - Disable turn off this device to save power for NIC -
$nics = get-wmiobject win32_networkadapter -filter "adaptertypeid = '0' , physicaladapter = 'true' , not description '%wireless%' , not description '%virtual%' , not description '%wifi%' , not description '%bluetooth%'" foreach ($nic in $nics) { $powermgmt = get-wmiobject mspower_deviceenable -namespace root\wmi | {$_.instancename -match [regex]::escape($nic.pnpdeviceid)} if ($powermgmt.enable -eq $true) { $powermgmt.enable = $false $powermgmt.psbase.put() } }
i have code, , works, psanalyzer says "for powershell 3.0 , above, use cim cmdlet perform same tasks wmi cmdlets. cim cmdlets comply ws-management (wsman) standards , common information model (cim) standard, enables cmdlets use same techniques manage windows computers , running other operating systems." how rewrite using cim cmdlet?
something should work fine you.
foreach ($nic in (get-netadapter -physical)){ $powersaving = get-ciminstance -classname mspower_deviceenable -namespace root\wmi | ? {$_.instancename -match [regex]::escape($nic.pnpdeviceid)} if ($powersaving.enable){ $powersaving.enable = $false $powersaving | set-ciminstance } }
Comments
Post a Comment