NIC Power Management – Exchange Server 2013 and 2016

Although Microsoft released this guidance a while back, NIC Power Management settings are almost always overlooked in an Exchange 2010 or 2013 environment. With the introduction of Exchange 2016, the guidance has not changed. I’ve put together a script built on a script that was written by Microsoft and modified to be a bit more flexible.

The Script

Here is the code for checking and setting your NIC to the correct setting for Exchange.

cls
write-host "Checking your NIC Power Settings now....." -ForegroundColor cyan;write-host " "
$NICs = Get-WmiObject -Class Win32_NetworkAdapter|Where-Object{$_.PNPDeviceID -notlike "ROOT\*" -and $_.Manufacturer -ne "Microsoft" -and $_.ConfigManagerErrorCode -eq 0 -and $_.ConfigManagerErrorCode -ne 22} 

Foreach($NIC in $NICs) {
	$NICName = $NIC.Name
	$DeviceID = $NIC.DeviceID
	If([Int32]$DeviceID -lt 10) {
		$DeviceNumber = "000"+$DeviceID
		} Else {
		$DeviceNumber = "00"+$DeviceID
	}

	$KeyPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\$DeviceNumber"
	
    If(Test-Path -Path $KeyPath) {
		$PnPCapabilities = (Get-ItemProperty -Path $KeyPath).PnPCapabilities
		If($PnPCapabilities -eq 0){Set-ItemProperty -Path $KeyPath -Name "PnPCapabilities" -Value 24 | Out-Null}
        If($PnPCapabilities -eq $null){Set-ItemProperty -Path $KeyPath -Name "PnPCapabilities" -Value 24 | Out-Null}
		If($PnPCapabilities -eq 24) {write-host "Power Management has already been " -NoNewline;write-host "disabled" -ForegroundColor Green}
        If($PnPCapabilities -ne 24) {
            Write-host "The value of "-nonewline;write-host $PnPCapabilities -foregroundcolor red -nonewline;write-host " was not expected.";write-host " "
            write-host "Would you like to change the Power Management setting for your NIC to none? [y or n] " -nonewline
            $choice = read-host
            if ($choice -eq 'y') {Set-ItemProperty -Path $KeyPath -Name "PnPCapabilities" -Value 24 | Out-Null}
            else {write-host " ";write-host "If this is an Exchange 2013/2016 server, you should turn off the Power Management settings." -ForegroundColor Yellow;write-host " "
            }
        }
    }			
}

Script In Action

Let’s say you run the script against your Exchange server, the script will look for some values that are configured for your NIC. These settings are stored within WMI. The script looks for the setting to be 24 (Power Management is disabled). If it is not, then it will see if the value is Null or 0. If these values are picked up, the script changes the number to 24. If something else is detected, the script will prompt you to make sure you want to change the setting. If you do not, you will receive a warning that you should change the setting:

PowerManagement

If we choose instead to configure it, we will see this:

PowerManagement4

Once configured and we run the script again, we will see it is already disbled:

PowerManagement3

However, make sure that you are running your PowerShell window as an Administrator, otherwise you will get this error:

PowerManagement2

Further Reading

Get-WmiObject
Set-ItemProperty

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s