Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetAdapterPowerManagement: new resource #501

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated build to use `Sampler.GitHubTasks` - Fixes [Issue #489](https://github.com/dsccommunity/NetworkingDsc/issues/489).
- Added support for publishing code coverage to `CodeCov.io` and
Azure Pipelines - Fixes [Issue #491](https://github.com/dsccommunity/NetworkingDsc/issues/491).
- Minor reformatting of code style for diffability.

### Added
- NetPowerManagement
- Allow configuration of power saving settings on network adapters.

## [8.2.0] - 2020-10-16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ function Get-TargetResource
$Ensure = 'Present'
)

$dnsClient = Get-DnsClient -InterfaceAlias $InterfaceAlias -ErrorAction SilentlyContinue
$dnsClient = Get-DnsClient `
-InterfaceAlias $InterfaceAlias `
-ErrorAction SilentlyContinue

$targetResource = @{
InterfaceAlias = $dnsClient.InterfaceAlias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function Get-TargetResource
) -join '' )

# Get the current Dns Client Global Settings
$netFirewallProfile = Get-NetFirewallProfile -Name $Name `
$netFirewallProfile = Get-NetFirewallProfile `
-Name $Name `
-ErrorAction Stop

# Generate the return object.
Expand Down Expand Up @@ -231,7 +232,8 @@ function Set-TargetResource
) -join '' )

# Get the current Firewall Profile Settings
$netFirewallProfile = Get-NetFirewallProfile -Name $Name `
$netFirewallProfile = Get-NetFirewallProfile `
-Name $Name `
-ErrorAction Stop

# Generate a list of parameters that will need to be changed.
Expand Down Expand Up @@ -442,7 +444,8 @@ function Test-TargetResource
$desiredConfigurationMatch = $true

# Get the current Dns Client Global Settings
$netFirewallProfile = Get-NetFirewallProfile -Name $Name `
$netFirewallProfile = Get-NetFirewallProfile `
-Name $Name `
-ErrorAction Stop

# Check each parameter
Expand Down
14 changes: 10 additions & 4 deletions source/DSCResources/DSC_IPAddress/DSC_IPAddress.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ function Set-TargetResource
try
{
# Apply the specified IP configuration
New-NetIPAddress @newNetIPAddressParameters -ErrorAction Stop
New-NetIPAddress @newNetIPAddressParameters `
-ErrorAction Stop
}
catch [Microsoft.Management.Infrastructure.CimException]
{
Expand All @@ -240,7 +241,8 @@ function Set-TargetResource
Setting New-NetIPaddress will throw [Microsoft.Management.Infrastructure.CimException] if
the IP address is already set. Need to check to make sure the IP is set on correct interface
#>
$verifyNetIPAddressAdapter = Get-NetIPAddress @verifyNetIPAddressAdapterParam -ErrorAction SilentlyContinue
$verifyNetIPAddressAdapter = Get-NetIPAddress @verifyNetIPAddressAdapterParam `
-ErrorAction SilentlyContinue

if ($verifyNetIPAddressAdapter.InterfaceAlias -eq $InterfaceAlias)
{
Expand Down Expand Up @@ -343,7 +345,9 @@ function Test-TargetResource
}
} # while

$ipAddressObject = Get-IPAddressPrefix -IPAddress $IPAddress -AddressFamily $AddressFamily
$ipAddressObject = Get-IPAddressPrefix `
-IPAddress $IPAddress `
-AddressFamily $AddressFamily

# Test if the IP Address passed is present
foreach ($singleIP in $ipAddressObject)
Expand Down Expand Up @@ -480,7 +484,9 @@ function Assert-ResourceProperty
{
$singleIP = ($singleIPAddress -split '/')[0]

Assert-IPAddress -Address $singleIP -AddressFamily $AddressFamily
Assert-IPAddress `
-Address $singleIP `
-AddressFamily $AddressFamily
}

foreach ($prefixLength in $prefixLengthArray)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ function Set-TargetResource

if ($currentConfig.SkipAsSource -ne $SkipAsSource)
{
Set-NetIPAddress -IPAddress $IPAddress -SkipAsSource $SkipAsSource
Set-NetIPAddress `
-IPAddress $IPAddress `
-SkipAsSource $SkipAsSource
}
}

Expand Down
24 changes: 18 additions & 6 deletions source/DSCResources/DSC_NetAdapterLso/DSC_NetAdapterLso.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function Get-TargetResource

try
{
$netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterLso `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down Expand Up @@ -131,7 +133,9 @@ function Set-TargetResource

try
{
$netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterLso `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand All @@ -154,7 +158,9 @@ function Set-TargetResource
$Name, $Protocol, $($netAdapter.V1IPv4Enabled.ToString()), $($State.ToString()) )
) -join '')

Set-NetAdapterLso -Name $Name -V1IPv4Enabled $State
Set-NetAdapterLso `
-Name $Name `
-V1IPv4Enabled $State
}
elseif ($Protocol -eq 'IPv4' -and $State -ne $netAdapter.IPv4Enabled)
{
Expand All @@ -164,7 +170,9 @@ function Set-TargetResource
$Name, $Protocol, $($netAdapter.IPv4Enabled.ToString()), $($State.ToString()) )
) -join '')

Set-NetAdapterLso -Name $Name -IPv4Enabled $State
Set-NetAdapterLso `
-Name $Name `
-IPv4Enabled $State
}
elseif ($Protocol -eq 'IPv6' -and $State -ne $netAdapter.IPv6Enabled)
{
Expand All @@ -174,7 +182,9 @@ function Set-TargetResource
$Name, $Protocol, $($netAdapter.IPv6Enabled.ToString()), $($State.ToString()) )
) -join '')

Set-NetAdapterLso -Name $Name -IPv6Enabled $State
Set-NetAdapterLso `
-Name $Name `
-IPv6Enabled $State
}
}
}
Expand Down Expand Up @@ -219,7 +229,9 @@ function Test-TargetResource

try
{
$netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterLso `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ function Set-TargetResource
$($script:localizedData.RenamingNetAdapterNameMessage -f $adapter.Name, $NewName)
) -join '')

$adapter | Rename-NetAdapter -NewName $NewName
$adapter | Rename-NetAdapter `
-NewName $NewName

Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
$($script:localizedData.NetAdapterNameRenamedMessage -f $NewName)
Expand Down
16 changes: 12 additions & 4 deletions source/DSCResources/DSC_NetAdapterRdma/DSC_NetAdapterRdma.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function Get-TargetResource
{
Write-Verbose -Message ($script:localizedData.GetNetAdapterRdmaMessage -f $Name)

$netAdapterRdma = Get-NetAdapterRdma -Name $Name -ErrorAction Stop
$netAdapterRdma = Get-NetAdapterRdma `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down Expand Up @@ -85,7 +87,9 @@ function Set-TargetResource
{
Write-Verbose -Message ($script:localizedData.GetNetAdapterRdmaMessage -f $Name)

$netAdapterRdma = Get-NetAdapterRdma -Name $Name -ErrorAction Stop
$netAdapterRdma = Get-NetAdapterRdma `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand All @@ -101,7 +105,9 @@ function Set-TargetResource
{
Write-Verbose -Message ($script:localizedData.SetNetAdapterRdmaMessage -f $Name, $Enabled)

Set-NetAdapterRdma -Name $Name -Enabled $Enabled
Set-NetAdapterRdma `
-Name $Name `
-Enabled $Enabled
}
}
}
Expand Down Expand Up @@ -137,7 +143,9 @@ function Test-TargetResource
{
Write-Verbose -Message ($script:localizedData.GetNetAdapterRdmaMessage -f $Name)

$netAdapterRdma = Get-NetAdapterRdma -Name $Name -ErrorAction Stop
$netAdapterRdma = Get-NetAdapterRdma `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down
20 changes: 15 additions & 5 deletions source/DSCResources/DSC_NetAdapterRsc/DSC_NetAdapterRsc.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function Get-TargetResource

try
{
$netAdapter = Get-NetAdapterRsc -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterRsc `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down Expand Up @@ -132,7 +134,9 @@ function Set-TargetResource

try
{
$netAdapter = Get-NetAdapterRsc -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterRsc `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand All @@ -155,7 +159,9 @@ function Set-TargetResource
$Name, $Protocol, $($netAdapter.IPv4Enabled.ToString()), $($State.ToString()) )
) -join '')

Set-NetAdapterRsc -Name $Name -IPv4Enabled $State
Set-NetAdapterRsc `
-Name $Name `
-IPv4Enabled $State
}
if ($Protocol -in ('IPv6', 'All') -and $State -ne $netAdapter.IPv6Enabled)
{
Expand All @@ -165,7 +171,9 @@ function Set-TargetResource
$Name, $Protocol, $($netAdapter.IPv6Enabled.ToString()), $($State.ToString()) )
) -join '')

Set-NetAdapterRsc -Name $Name -IPv6Enabled $State
Set-NetAdapterRsc `
-Name $Name `
-IPv6Enabled $State
}
}
}
Expand Down Expand Up @@ -210,7 +218,9 @@ function Test-TargetResource

try
{
$netAdapter = Get-NetAdapterRsc -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterRsc `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down
16 changes: 12 additions & 4 deletions source/DSCResources/DSC_NetAdapterRss/DSC_NetAdapterRss.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function Get-TargetResource

try
{
$netAdapter = Get-NetAdapterRss -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterRss `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down Expand Up @@ -97,7 +99,9 @@ function Set-TargetResource

try
{
$netAdapter = Get-NetAdapterRss -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterRss `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand All @@ -120,7 +124,9 @@ function Set-TargetResource
$Name, $Enabled, $($netAdapter.Enabled.ToString()), $($Enabled.ToString()) )
) -join '')

Set-NetAdapterRss -Name $Name -Enabled:$Enabled
Set-NetAdapterRss `
-Name $Name `
-Enabled:$Enabled
}
}
}
Expand Down Expand Up @@ -157,7 +163,9 @@ function Test-TargetResource

try
{
$netAdapter = Get-NetAdapterRss -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterRss `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down
17 changes: 13 additions & 4 deletions source/DSCResources/DSC_NetAdapterState/DSC_NetAdapterState.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ function Get-TargetResource

try
{
$netAdapter = Get-NetAdapter -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapter `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand Down Expand Up @@ -115,7 +117,9 @@ function Set-TargetResource

try
{
$netAdapter = Get-NetAdapter -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapter `
-Name $Name `
-ErrorAction Stop
}
catch
{
Expand All @@ -131,11 +135,16 @@ function Set-TargetResource
{
if ($State -eq 'Disabled')
{
Disable-NetAdapter -Name $Name -Confirm:$false -ErrorAction Stop
Disable-NetAdapter `
-Name $Name `
-Confirm:$false `
-ErrorAction Stop
}
else
{
Enable-NetAdapter -Name $Name -ErrorAction Stop
Enable-NetAdapter `
-Name $Name `
-ErrorAction Stop
}
}
catch
Expand Down
Loading