dsccommunity / dsccommunity/NetworkingDsc

Need Network Power Settings

Open
#188 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in progress resource proposal
Dominant language
PowerShell
Stars
235
Forks
93
PR merge metrics
No merged PRs in 30d

Description

Need the ability to disable power saving mode on NIC.

I use this
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$ServerName
)

#Write-Verbose "Use this cmdlet to deliver information about command processing."

#Write-Debug "Use this cmdlet to write debug information while troubleshooting."
$nic = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'}
$powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)}


$returnValue = @{
	ServerName = $ServerName
    NICPowerSaving = $powerMgmt.Enable
}

$returnValue

}

function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[System.String]
$ServerName,

	[ValidateSet("Present","Absent")]
	[System.String]
	$Ensure
)

Write-Verbose "Setting the NIC power Management setting."

#Write-Debug "Use this cmdlet to write debug information while troubleshooting."

Write-Verbose "Configuring the SQL alerts ."
If ($Ensure -eq 'Present'){
    DisableNICPowerManagement -ServerName $ServerName
}ELSE{
    EnableNICPowerManagement -ServerName $ServerName -InstanceName $InstanceName -OperatorName $OperatorName -NotificationMethod $NotificationMethod
}

}

function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$ServerName,

	[ValidateSet("Present","Absent")]
	[System.String]
	$Ensure
)

Write-Verbose "Checking to see if the power setting on the NIC."

#Write-Debug "Use this cmdlet to write debug information while troubleshooting."

$nic = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'}
$powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)}

If ($Ensure -eq 'Present'){
    If ($powerMgmt.Enable -eq $false){
        Write-Verbose "NIC Power Management setting is disabled."
        $result = $true
    }ELSE{
        Write-Verbose "NIC Power Management setting is not disabled. - Disabling"
        $result = $false
    }
}

If ($Ensure -eq 'Absent'){
    If ($powerMgmt.Enable -eq $false) {
        Write-Verbose "NIC Power Management setting is disabled. - Enabling."
        $result = $false
    }ELSE{
        Write-Verbose "NIC Power Management setting is not disabled."
        $result = $true
    }
}

$result

}

Export-ModuleMember -Function *-TargetResource

Function DisableNICPowerManagement{
param ($ServerName)
Write-Verbose "Disabling the NIC Power Management setting."
$nics = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'}

    foreach ($nic in $nics)
    {
        $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)}
        $powerMgmt.Enable = $False
        $powerMgmt.psbase.Put() | Out-Null
    }

}
#DisableNICPowerManagement -ServerName 'SSVdbOlyTest01'

Function EnableNICPowerManagement{
param ($ServerName)

Write-Verbose "Enabling the NIC Power Management setting."
$nics = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'}

    foreach ($nic in $nics)
    {
        $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)}
        $powerMgmt.Enable = $True
        $powerMgmt.psbase.Put() | Out-Null
    }

}
#EnableNICPowerManagement -ServerName 'SSVdbOlyTest01'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Get-TargetResource, Set-TargetResource, and Test-TargetResource entry points shown in the issue body, then review the repository's existing DSC resource layout. Check how Win32_NetworkAdapter and MSPower_DeviceEnable are used. Done means the resource can report, test, and configure NIC power-saving state consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.