Skip to content

Commit

Permalink
Expose -IncludeHidden parameter
Browse files Browse the repository at this point in the history
NetAdapter module Cmdlets have an -IncludeHidden flag which allows access to adapters which are hidden; expose that flag here.

- Add flag to MOF schemas
- Add function parameter and comment based help

- NetAdapterName should now be working
- NetAdapterRdma should now be working
- NetAdapterRss should now be working
- NetAdapterState should now be working
  • Loading branch information
gaelicWizard committed May 20, 2021
1 parent 983c54b commit b44569c
Show file tree
Hide file tree
Showing 26 changed files with 428 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,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

0 comments on commit b44569c

Please sign in to comment.