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

Allow configuration of hidden network adapters #500

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f8c2dcd
Clean spurious newline at file beginning
gaelicWizard May 19, 2021
e98d1aa
Reformat whitespace for diffability to match other modues
gaelicWizard May 20, 2021
0572312
Minor code style reformatting.
gaelicWizard May 20, 2021
a219b1f
Reformat whitespace for diffability to match other modues
gaelicWizard May 20, 2021
25b88a3
Find-NetworkAdapter: add -IncludeHidden parameter
gaelicWizard May 22, 2021
bf6235a
NetAdapterName: add IncludeHidden property
gaelicWizard May 22, 2021
ed1227c
DefaultGatewayAddress: use Find-NetworkAdapter
gaelicWizard May 22, 2021
fba8475
NetAdapterAdvancedProperty: include hidden adapters
gaelicWizard May 22, 2021
d24c923
NetAdapterBinding: include hidden adapters
gaelicWizard May 22, 2021
fde2713
NetAdapterbinding: use Find-NetworkAdapter
gaelicWizard May 22, 2021
ab3a323
NetAdapterLso: include hidden adapters
gaelicWizard May 22, 2021
5708b03
NetAdapterRdma: include hidden adapeters
gaelicWizard May 22, 2021
9287115
NetAdapterRsc: include hidden adapters
gaelicWizard May 22, 2021
caa645d
NetAdapterRss: include hidden adapters
gaelicWizard May 22, 2021
586ccc8
NetAdapterState: use Find-NetworkAdapter
gaelicWizard May 22, 2021
d89ec2e
NetAdapterState: include hidden adapters
gaelicWizard May 22, 2021
8ff8f52
NetConnectionProfile: use Find-NetworkAdapter
gaelicWizard May 22, 2021
4f16312
Route: use Find-NetworkAdapter
gaelicWizard May 22, 2021
3c46089
WinsServerAddress: use Find-NetworkAdapter
gaelicWizard May 22, 2021
c3df66c
Allow configuration of hidden network adapters.
gaelicWizard May 22, 2021
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 @@ -292,7 +292,7 @@ function Assert-ResourceProperty
$Address
)

if (-not (Get-NetAdapter | Where-Object -Property Name -EQ $InterfaceAlias ))
if (-not (Find-NetworkAdapter -Name $InterfaceAlias ))
{
New-InvalidOperationException `
-Message ($script:localizedData.InterfaceNotAvailableError -f $InterfaceAlias)
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
14 changes: 10 additions & 4 deletions source/DSCResources/DSC_FirewallProfile/DSC_FirewallProfile.psm1
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 All @@ -243,7 +245,10 @@ function Set-TargetResource
$parameterNewValue = (Get-Variable -Name ($parameter.name)).Value

if ($PSBoundParameters.ContainsKey($parameter.Name) `
-and (Compare-Object -ReferenceObject $parameterSourceValue -DifferenceObject $parameterNewValue -SyncWindow 0))
-and (Compare-Object `
-ReferenceObject $parameterSourceValue `
-DifferenceObject $parameterNewValue `
-SyncWindow 0))
{
$changeParameters += @{
$($parameter.name) = $parameterNewValue
Expand Down Expand Up @@ -442,7 +447,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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function Get-TargetResource
{
$netAdapterAdvancedProperty = Get-NetAdapterAdvancedProperty `
-Name $networkAdapterName `
-IncludeHidden:$true `
-RegistryKeyword $RegistryKeyword `
-ErrorAction Stop
}
Expand Down Expand Up @@ -118,6 +119,7 @@ function Set-TargetResource
{
$netAdapterAdvancedProperty = Get-NetAdapterAdvancedProperty `
-Name $networkAdapterName `
-IncludeHidden:$true `
-RegistryKeyword $RegistryKeyword `
-ErrorAction Stop
}
Expand Down Expand Up @@ -146,6 +148,7 @@ function Set-TargetResource
Set-NetAdapterAdvancedProperty `
-RegistryValue $RegistryValue `
-Name $networkAdapterName `
-IncludeHidden:$true `
-RegistryKeyword $RegistryKeyword
}
}
Expand Down Expand Up @@ -192,6 +195,7 @@ function Test-TargetResource
{
$netAdapterAdvancedProperty = Get-NetAdapterAdvancedProperty `
-Name $networkAdapterName `
-IncludeHidden:$true `
-RegistryKeyword $RegistryKeyword `
-ErrorAction Stop
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ function Set-TargetResource

if ($State -eq 'Enabled')
{
Enable-NetAdapterBinding @PSBoundParameters
Enable-NetAdapterBinding @PSBoundParameters `
-IncludeHidden:$true

Write-Verbose -Message ( @("$($MyInvocation.MyCommand): "
$($script:localizedData.NetAdapterBindingEnabledMessage -f `
Expand All @@ -135,7 +136,8 @@ function Set-TargetResource
}
else
{
Disable-NetAdapterBinding @PSBoundParameters
Disable-NetAdapterBinding @PSBoundParameters `
-IncludeHidden:$true

Write-Verbose -Message ( @("$($MyInvocation.MyCommand): "
$($script:localizedData.NetAdapterBindingDisabledMessage -f `
Expand Down Expand Up @@ -260,7 +262,7 @@ function Get-Binding
$State = 'Enabled'
)

if (-not (Get-NetAdapter -Name $InterfaceAlias -ErrorAction SilentlyContinue))
if (-not (Find-NetworkAdapter -Name $InterfaceAlias -ErrorAction SilentlyContinue))
{
New-InvalidArgumentException `
-Message ($script:localizedData.InterfaceNotAvailableError -f $InterfaceAlias) `
Expand All @@ -269,6 +271,7 @@ function Get-Binding

$binding = Get-NetAdapterBinding `
-InterfaceAlias $InterfaceAlias `
-IncludeHidden:$true `
-ComponentId $ComponentId `
-ErrorAction Stop

Expand Down
30 changes: 24 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,10 @@ function Get-TargetResource

try
{
$netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterLso `
-Name $Name `
-IncludeHidden:$true `
-ErrorAction Stop
}
catch
{
Expand Down Expand Up @@ -131,7 +134,10 @@ function Set-TargetResource

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

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

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

Set-NetAdapterLso -Name $Name -IPv6Enabled $State
Set-NetAdapterLso `
-Name $Name `
-IncludeHidden:$true `
-IPv6Enabled $State
}
}
}
Expand Down Expand Up @@ -219,7 +234,10 @@ function Test-TargetResource

try
{
$netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop
$netAdapter = Get-NetAdapterLso `
-Name $Name `
-IncludeHidden:$true `
-ErrorAction Stop
}
catch
{
Expand Down
28 changes: 27 additions & 1 deletion source/DSCResources/DSC_NetAdapterName/DSC_NetAdapterName.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
.PARAMETER InterfaceDescription
This is the interface description of the network adapter to find.

.PARAMETER IncludeHidden
This switch indicates the adapter to find may be hidden.

.PARAMETER InterfaceIndex
This is the interface index of the network adapter to find.

Expand Down Expand Up @@ -84,6 +87,10 @@ function Get-TargetResource
[System.String]
$InterfaceDescription,

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

[Parameter()]
[System.UInt32]
$InterfaceIndex,
Expand Down Expand Up @@ -111,6 +118,7 @@ function Get-TargetResource

$adapter = Find-NetworkAdapter `
-Name $NewName `
-IncludeHidden:$IncludeHidden `
-ErrorAction SilentlyContinue

if (-not $adapter)
Expand All @@ -136,6 +144,7 @@ function Get-TargetResource
Status = $adapter.Status
MacAddress = $adapter.MacAddress
InterfaceDescription = $adapter.InterfaceDescription
IncludeHidden = $IncludeHidden
InterfaceIndex = $adapter.InterfaceIndex
InterfaceGuid = $adapter.InterfaceGuid
DriverDescription = $adapter.DriverDescription
Expand Down Expand Up @@ -168,6 +177,9 @@ function Get-TargetResource
.PARAMETER InterfaceDescription
This is the interface description of the network adapter to find.

.PARAMETER IncludeHidden
This switch indicates the adapter to find may be hidden.

.PARAMETER InterfaceIndex
This is the interface index of the network adapter to find.

Expand Down Expand Up @@ -218,6 +230,10 @@ function Set-TargetResource
[System.String]
$InterfaceDescription,

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

[Parameter()]
[System.UInt32]
$InterfaceIndex,
Expand Down Expand Up @@ -253,7 +269,9 @@ function Set-TargetResource
$($script:localizedData.RenamingNetAdapterNameMessage -f $adapter.Name, $NewName)
) -join '')

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

Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
$($script:localizedData.NetAdapterNameRenamedMessage -f $NewName)
Expand Down Expand Up @@ -283,6 +301,9 @@ function Set-TargetResource
.PARAMETER InterfaceDescription
This is the interface description of the network adapter to find.

.PARAMETER IncludeHidden
This switch indicates the adapter to find may be hidden.

.PARAMETER InterfaceIndex
This is the interface index of the network adapter to find.

Expand Down Expand Up @@ -334,6 +355,10 @@ function Test-TargetResource
[System.String]
$InterfaceDescription,

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

[Parameter()]
[System.UInt32]
$InterfaceIndex,
Expand Down Expand Up @@ -364,6 +389,7 @@ function Test-TargetResource
# Can an adapter be found with the new name?
$adapterWithNewName = Find-NetworkAdapter `
-Name $NewName `
-IncludeHidden:$IncludeHidden `
-Verbose:$Verbose `
-ErrorAction SilentlyContinue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class DSC_NetAdapterName : OMI_BaseResource
[Write, Description("This is the status of the network adapter to find."), ValueMap{"Up", "Disconnected", "Disabled"}, Values{"Up", "Disconnected", "Disabled"}] String Status;
[Write, Description("This is the MAC address of the network adapter to find.")] String MacAddress;
[Write, Description("This is the interface description of the network adapter to find.")] String InterfaceDescription;
[Write, Description("This switch indicates the adapter to find may be hidden.")] Boolean IncludeHidden;
[Write, Description("This is the interface index of the network adapter to find.")] UInt32 InterfaceIndex;
[Write, Description("This is the interface GUID of the network adapter to find.")] String InterfaceGuid;
[Write, Description("This is the driver description of the network adapter.")] String DriverDescription;
Expand Down
Loading