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:
If we choose instead to configure it, we will see this:
Once configured and we run the script again, we will see it is already disbled:
However, make sure that you are running your PowerShell window as an Administrator, otherwise you will get this error:
Further Reading
Get-WmiObject
Set-ItemProperty
$NICproperties = Get-ItemProperty -Path “HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\*” -ErrorAction SilentlyContinue | Where-Object {$_.ProviderName -ne “Microsoft”}
ForEach ($_ in $NICproperties) {
Set-ItemProperty -Path $_.PSPath -Name “PnPCapabilities” -Value 24 -Force
}
Is this a code suggestion? Curios as you don’t provide any information on this code snippet.