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

Expose -IncludeHidden parameter #495

Draft
wants to merge 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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).
- Allow configuration of hidden network adapters.

## [8.2.0] - 2020-10-16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ function Test-TargetResource
.PARAMETER InterfaceAlias
Alias of the network interface for which the default gateway address is set.

.PARAMETER IncludeHidden
Whether to include hidden network adapters.

.PARAMETER AddressFamily
IP address family.

Expand All @@ -282,6 +285,10 @@ function Assert-ResourceProperty
[System.String]
$InterfaceAlias,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter()]
[ValidateSet('IPv4', 'IPv6')]
[System.String]
Expand All @@ -292,7 +299,7 @@ function Assert-ResourceProperty
$Address
)

if (-not (Get-NetAdapter | Where-Object -Property Name -EQ $InterfaceAlias ))
if (-not (Get-NetAdapter -IncludeHidden:$IncludeHidden | Where-Object -Property Name -EQ $InterfaceAlias ))
{
New-InvalidOperationException `
-Message ($script:localizedData.InterfaceNotAvailableError -f $InterfaceAlias)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
.PARAMETER NetworkAdapterName
Specifies the name of the network adapter to set the advanced property for.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER RegistryKeyword
Specifies the registry keyword that should be in desired state.

Expand All @@ -33,6 +36,10 @@ function Get-TargetResource
[System.String]
$NetworkAdapterName,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[System.String]
$RegistryKeyword,
Expand All @@ -51,6 +58,7 @@ function Get-TargetResource
{
$netAdapterAdvancedProperty = Get-NetAdapterAdvancedProperty `
-Name $networkAdapterName `
-IncludeHidden:$IncludeHidden `
-RegistryKeyword $RegistryKeyword `
-ErrorAction Stop
}
Expand Down Expand Up @@ -85,6 +93,9 @@ function Get-TargetResource
.PARAMETER NetworkAdapterName
Specifies the name of the network adapter to set the advanced property for.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER RegistryKeyword
Specifies the registry keyword that should be in desired state.

Expand All @@ -100,6 +111,10 @@ function Set-TargetResource
[System.String]
$NetworkAdapterName,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[System.String]
$RegistryKeyword,
Expand All @@ -118,6 +133,7 @@ function Set-TargetResource
{
$netAdapterAdvancedProperty = Get-NetAdapterAdvancedProperty `
-Name $networkAdapterName `
-IncludeHidden:$IncludeHidden `
-RegistryKeyword $RegistryKeyword `
-ErrorAction Stop
}
Expand Down Expand Up @@ -146,6 +162,7 @@ function Set-TargetResource
Set-NetAdapterAdvancedProperty `
-RegistryValue $RegistryValue `
-Name $networkAdapterName `
-IncludeHidden:$IncludeHidden `
-RegistryKeyword $RegistryKeyword
}
}
Expand All @@ -158,6 +175,9 @@ function Set-TargetResource
.PARAMETER NetworkAdapterName
Specifies the name of the network adapter to set the advanced property for.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER RegistryKeyword
Specifies the registry keyword that should be in desired state.

Expand All @@ -174,6 +194,10 @@ function Test-TargetResource
[System.String]
$NetworkAdapterName,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[System.String]
$RegistryKeyword,
Expand All @@ -192,6 +216,7 @@ function Test-TargetResource
{
$netAdapterAdvancedProperty = Get-NetAdapterAdvancedProperty `
-Name $networkAdapterName `
-IncludeHidden:$IncludeHidden `
-RegistryKeyword $RegistryKeyword `
-ErrorAction Stop
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class DSC_NetAdapterAdvancedProperty : OMI_BaseResource
{
[Key, Description("Specifies the name of the network adapter to set the advanced property for.")] String NetworkAdapterName;
[Write, Description("This switch will causes hidden network adapters to be included in the search.")] Boolean IncludeHidden;
[Key, Description("Specifies the registry keyword that should be in desired state.")] String RegistryKeyword;
[Required, Description("Specifies the value of the registry keyword.")] String RegistryValue;
[Read, Description("Output Display value of selected RegistryKeyword.")] String DisplayValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
.PARAMETER InterfaceAlias
Specifies the alias of a network interface. Supports the use of '*'.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER ComponentId
Specifies the underlying name of the transport or filter in the following
form - ms_xxxx, such as ms_tcpip.
Expand All @@ -35,6 +38,10 @@ function Get-TargetResource
[System.String]
$InterfaceAlias,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
Expand Down Expand Up @@ -86,6 +93,9 @@ function Get-TargetResource
.PARAMETER InterfaceAlias
Specifies the alias of a network interface. Supports the use of '*'.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER ComponentId
Specifies the underlying name of the transport or filter in the following
form - ms_xxxx, such as ms_tcpip.
Expand All @@ -103,6 +113,10 @@ function Set-TargetResource
[System.String]
$InterfaceAlias,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
Expand Down Expand Up @@ -151,6 +165,9 @@ function Set-TargetResource
.PARAMETER InterfaceAlias
Specifies the alias of a network interface. Supports the use of '*'.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER ComponentId
Specifies the underlying name of the transport or filter in the following
form - ms_xxxx, such as ms_tcpip.
Expand All @@ -169,6 +186,10 @@ function Test-TargetResource
[System.String]
$InterfaceAlias,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
Expand Down Expand Up @@ -231,6 +252,9 @@ function Test-TargetResource
.PARAMETER InterfaceAlias
Specifies the alias of a network interface. Supports the use of '*'.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER ComponentId
Specifies the underlying name of the transport or filter in the following
form - ms_xxxx, such as ms_tcpip.
Expand All @@ -249,6 +273,10 @@ function Get-Binding
[System.String]
$InterfaceAlias,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
Expand All @@ -260,7 +288,7 @@ function Get-Binding
$State = 'Enabled'
)

if (-not (Get-NetAdapter -Name $InterfaceAlias -ErrorAction SilentlyContinue))
if (-not (Get-NetAdapter -Name $InterfaceAlias -IncludeHidden:$IncludeHidden -ErrorAction SilentlyContinue))
{
New-InvalidArgumentException `
-Message ($script:localizedData.InterfaceNotAvailableError -f $InterfaceAlias) `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class DSC_NetAdapterBinding : OMI_BaseResource
{
[Key, Description("Specifies the alias of a network interface. Supports the use of '*'.")] string InterfaceAlias;
[Write, Description("This switch will causes hidden network adapters to be included in the search.")] Boolean IncludeHidden;
[Key, Description("Specifies the underlying name of the transport or filter in the following form - ms_xxxx, such as ms_tcpip.")] string ComponentId;
[Write, Description("Specifies if the component ID for the Interface should be Enabled or Disabled."), ValueMap{"Enabled", "Disabled"}, Values{"Enabled", "Disabled"}] string State;
[Read, Description("Returns the current state of the component ID for the Interfaces."), ValueMap{"Enabled", "Disabled","Mixed"}, Values{"Enabled", "Disabled","Mixed"}] string CurrentState;
Expand Down
45 changes: 39 additions & 6 deletions source/DSCResources/DSC_NetAdapterLso/DSC_NetAdapterLso.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
.PARAMETER Name
Specifies the name of the network adapter to check.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER Protocol
Specifies which protocol to target.

Expand All @@ -33,6 +36,10 @@ function Get-TargetResource
[System.String]
$Name,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[ValidateSet('V1IPv4', 'IPv4', 'IPv6')]
[System.String]
Expand All @@ -50,7 +57,9 @@ function Get-TargetResource

try
{
$netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterLso -Name $Name `
-IncludeHidden:$IncludeHidden `
-ErrorAction Stop
}
catch
{
Expand Down Expand Up @@ -99,6 +108,9 @@ function Get-TargetResource
.PARAMETER Name
Specifies the name of the network adapter to check.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER Protocol
Specifies which protocol to target.

Expand All @@ -114,6 +126,10 @@ function Set-TargetResource
[System.String]
$Name,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[ValidateSet('V1IPv4', 'IPv4', 'IPv6')]
[System.String]
Expand All @@ -131,7 +147,9 @@ function Set-TargetResource

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

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

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

Set-NetAdapterLso -Name $Name -IPv6Enabled $State
Set-NetAdapterLso -Name $Name `
-IncludeHidden:$IncludeHidden `
-ErrorAction Stop
}
}
}
Expand All @@ -186,6 +210,9 @@ function Set-TargetResource
.PARAMETER Name
Specifies the name of the network adapter to check.

.PARAMETER IncludeHidden
This switch will causes hidden network adapters to be included in the search.

.PARAMETER Protocol
Specifies which protocol to target.

Expand All @@ -202,6 +229,10 @@ function Test-TargetResource
[System.String]
$Name,

[Parameter()]
[System.Boolean]
$IncludeHidden = $false,

[Parameter(Mandatory = $true)]
[ValidateSet('V1IPv4', 'IPv4', 'IPv6')]
[System.String]
Expand All @@ -219,7 +250,9 @@ function Test-TargetResource

try
{
$netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterLso -Name $Name `
-IncludeHidden:$IncludeHidden `
-ErrorAction Stop
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class DSC_NetAdapterLso : OMI_BaseResource
{
[Key, Description("Specifies the name of network adapter.")] String Name;
[Write, Description("This switch will causes hidden network adapters to be included in the search.")] Boolean IncludeHidden;
[Key, Description("Specifies which protocol to make changes to."), ValueMap{"V1IPv4","IPv4","IPv6"}, Values{"V1IPv4","IPv4","IPv6"}] String Protocol;
[Required, Description("Specifies whether LSO should be enabled or disabled.")] Boolean State;
};
Loading