Disable turn off this device to save power for NIC Power Management (PowerShell)

This PowerShell Script illustrates how to disable "turn off this device to save power" feature in Power Management.

 
 
 
 
 
4.5 Star
(10)
13,887 times
Add to favorites
Hardware
7/29/2013
E-mail Twitter del.icio.us Digg Facebook
  • 2012 Version
    4 Posts | Last post October 24, 2019
    • I agree with Manfred538; the assumption of the registry value either being null,0 or 24 doesn't seem safe. In fact when I disable the setting via GUI (in 2008R2 and 2012), the value gets set to 280 (256+24) on servers where the value was previously non-existent
      
      Here is my crack at it (using 2012 commands)
      $adapters = get-netadapter -physical
      
      foreach ($a in $adapters)
      {
      	$pnp = $a | Get-NetAdapterAdvancedProperty -RegistryKeyword "PnPCapabilities" -AllProperties
      	
      	if (!($pnp)
      	{
      		#need to add value, set to 280
      		$new = 280
      		$a | New-NetAdapterAdvancedProperty -RegistryKeyword "PnPCapabilities" -RegistryValue $new -RegistryDataType REG_DWORD
      		$a | restart-netadapter
      
      	}
      	elseif (([int]"$($pnp.RegistryValue)" -band 24) -eq 0)
      	{
      		#power is not disabled, take current value and add 24
      		$new = [int]"$($pnp.RegistryValue)" -bor 24
      		$a | Remove-NetAdapterAdvancedProperty -RegistryKeyword "PnPCapabilities" -AllProperties
      		$a | New-NetAdapterAdvancedProperty -RegistryKeyword "PnPCapabilities" -RegistryValue $new -RegistryDataType REG_DWORD
      		$a | restart-netadapter
      	}
      	elseif (([int]"$($pnp.RegistryValue)" -band 24) -eq 24)
      	{
      		#power saving is disabled, we are good
      	}
      	else
      	{
      		#unknown setting state, leave alone
      	}
      
      }
    • https://support.microsoft.com/en-us/help/2740020/information-about-power-management-setting-on-a-network-adapter
      
      Setting PnPCapabilities to 0x18 (24) should be enough following the above article.
    • I deleted some unnecessary lines in the script of OneScript Team because we do not have config manager. And it worked for me on all NIC (Wireless and Wire):
      Function Disable-OSCNetAdapterPnPCaptitlies
      {
      	#find only physical network,if value of properties of adaptersConfigManagerErrorCode is 0,  it means device is working properly. 
      	#even covers enabled or disconnected devices.
      	#if the value of properties of configManagerErrorCode is 22, it means the adapter was disabled. 
      	$PhysicalAdapters = Get-WmiObject -Class Win32_NetworkAdapter|Where-Object{$_.PNPDeviceID -notlike "ROOT\*" `
      	-and $_.Manufacturer -ne "Microsoft"} 
      	
      	Foreach($PhysicalAdapter in $PhysicalAdapters)
      	{$PhysicalAdapterName = $PhysicalAdapter.Name
      		#check the unique device id number of network adapter in the currently environment.
      		$DeviceID = $PhysicalAdapter.DeviceID
      		If([Int32]$DeviceID -lt 10)
      		{$AdapterDeviceNumber = "000"+$DeviceID
      		}
      		Else
      		{$AdapterDeviceNumber = "00"+$DeviceID
      		}
      		#check whether the registry path exists.
      		$KeyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\$AdapterDeviceNumber"
      		If(Test-Path -Path $KeyPath)
      		{$PnPCapabilitiesValue = (Get-ItemProperty -Path $KeyPath).PnPCapabilities
      			If($PnPCapabilitiesValue -eq 24)
      			{Write-Warning """$PhysicalAdapterName"" - The option ""Allow the computer to turn off this device to save power"" has been disabled already."
      			}
      			If($PnPCapabilitiesValue -ne 24)
      			{#check whether change value was successed.
      			Try
      				{#setting the value of properties of PnPCapabilites to 24, it will disable save power option.
      					Set-ItemProperty -Path $KeyPath -Name "PnPCapabilities" -Value 24 | Out-Null
      	Write-Host """$PhysicalAdapterName"" - The option ""Allow the computer to turn off this device to save power"" was disabled."
      				}
      				
    • Catch
      				{Write-Host "Setting the value of properties of PnpCapabilities failed." -ForegroundColor Red
      				}
      			}
      			If($PnPCapabilitiesValue -eq $null)
      			{Try
      				{New-ItemProperty -Path $KeyPath -Name "PnPCapabilities" -Value 24 -PropertyType DWord | Out-Null
      Write-Host """$PhysicalAdapterName"" - The option ""Allow the computer to turn off this device to save power"" was disabled."					
      				}
      				Catch
      				{Write-Host "Setting the value of properties of PnpCapabilities failed." -ForegroundColor Red }
      			}
      		}
      		Else
      		{Write-Warning "The path ($KeyPath) not found."
      		}
      	}
      }
      Disable-OSCNetAdapterPnPCaptitlies
  • Windows 10
    1 Posts | Last post October 03, 2016
    • Hello,
      
      I'm trying to use this script with Windows 10, but without success.
      I've added this line :
      $shell.popup("PnPCapabilities : $NewPnPCapabilities")
      after and before this line to see if The PnpCapabilities data changed :
      Set-ItemProperty -path "HKLM:$KeyPath\$SubKey" -name "pnpCapabilities" -value $NewPnPCapabilities -Type "DWORD"
      
      But I get the same data before and after the set-itemproperty.
      I've run the script with administrator right and i ve set the policy execution of pwrshell at unrestricted. 
      
      Can you help me to modify the script for being using in Windows 10 please ?
      
      Thanks ;)
      
  • How does one modify this script to disable wireless NIC’s?
    2 Posts | Last post November 12, 2015
    • Does one modify these lines to disable wireless NIC's?
      $PhysicalAdapters = Get-WmiObject -Class Win32_NetworkAdapter|Where-Object{$_.PNPDeviceID -notlike "ROOT\*" `
      	-and $_.Manufacturer -ne "Microsoft" -and $_.ConfigManagerErrorCode -eq 0 -and $_.ConfigManagerErrorCode -ne 22}
    • No, I found out that line gets all of the NIC's, but later on, the script only checks for zero, 24, or nil. I also needed to check for wireless default: 16, and I didn't need the function to stop after finding the Ethernet. Therefore, I used a switch statement to check for all three conditions that needed to be changed:
      
      switch ($PnPCapabilitiesValue)
          {
              0 {Set-ItemProperty -Path $KeyPath -Name "PnPCapabilities" -Value 24 | Out-Null}
              16 {Set-ItemProperty -Path $KeyPath -Name "PnPCapabilities" -Value 24 | Out-Null}
              $null {New-ItemProperty -Path $KeyPath -Name "PnPCapabilities" -Value 24 -PropertyType DWord | Out-Null}
          }
  • There is a working script here:
    1 Posts | Last post October 30, 2015
    • Set $PNPCapabilities to whatever value desired (24 disables power management)and run as the script administrator
      
      http://ephingadmin.com/a-configmgr-admins-guide-to-wol-magic-part-two/
  • Problem in script
    5 Posts | Last post October 16, 2015
    • The script seems incorrect.
      As I have tested, "Allow the computer to turn off this device to save power" toggles the first bit of PnPCapabilities. This would be a value of "8".
      The script checks "PnPCapabilities" for a total value of "24" or "0", where it should only check for the lowest bit, since other options (or future options) could result in higher values.
      My default value is HEX 10 (16), not "0".
      
    • Can't seem to find an edit for prev post, I will try to rewrite the script using an bOR operator to turn the lower bit to 1.
    • Here is my script; no output, no reboot functions, since it is run silent from a deployment mechanism (SCCM). Will be effective after a reboot.
      
      #enumerate Network Class keys, the subkeys contain all network adapters, both virtual/software and physical devices
      $KeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
      $SubKeys = get-childitem -name -path "HKLM:\$KeyPath" -ErrorAction "SilentlyContinue" -Exclude "Properties"
      
      Foreach ($SubKey in $SubKeys)          #loop through all devices
          {
          $NetworkCardSettings = Get-ItemProperty "HKLM:\$KeyPath\$SubKey"          #get NetworkCard info
          If ($NetworkCardSettings.ComponentId -and $NetworkCardSettings.ComponentId.StartsWith("pci"))    #Check existance of ComponentId, and check if it is a physical device)
              {
              $NewPnPCapabilities = $NetworkCardSettings.pnpCapabilities -bOR "8"          #Set the first bit to 1, regardless of what current value is
              Set-ItemProperty -path "HKLM:$KeyPath\$SubKey" -name "pnpCapabilities" -value $NewPnPCapabilities -Type "DWORD"
              }
          }
    • Hi,
      
      You could also disable and enable the wifi adapters within the script. I actually used powershell to enable the setting, but in principle it work the same.
      
      $WifiAdapters = Get-WmiObject -Namespace root\wmi -Class MSNdis_PhysicalMediumType -Filter `
                      "(NdisPhysicalMediumType=1 OR NdisPhysicalMediumType=8 OR NdisPhysicalMediumType=9) AND NOT InstanceName LIKE '%virtual%'"
      
      Write-Host -Foregroundcolor Green "Found $(($WifiAdapters | Measure ).Count + 0) wifi adapters"
      foreach ($WifiAdapter in $WifiAdapters) {
      $PhysicalAdapter = Get-WmiObject -Class Win32_NetworkAdapter -Filter "Name='$($WifiAdapter.InstanceName)'" -Property * |`
       ? {$_.ConfigManagerErrorCode -eq 0 -and $_.ConfigManagerErrorCode -ne 22}
      
      $PhysicalAdapter.Disable() | out-null
       $PhysicalAdapter.Enable() | out-null
      }
      This should for example disable/enable all non disabled, configired WLAN  adapters, if the script run with elevated credentials
    • I used Manfred538s code and it worked great.
  • Why doesn't this work? Did you guys test it?
    1 Posts | Last post October 01, 2014
    • Followed the instruction as given...the command completes but without any output. I'm not prompted to reboot or given a failure message. No effect on the adapter power setting, either. 
      
      Did you guys actually test the instructions? This seems fairly simple. I don't think I missed anything..it just doesn't work, as presented. (Windows 7 32bit Pro)