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

Proposed fix for Issue #413 #414

Merged
merged 27 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d107244
Proposed fix for Issue #413
Jul 29, 2019
724b69a
Corrected capitals in if statement per PSA rules
Jul 29, 2019
57f3425
Broke logic for filter out into Format-Win32NetworkADapterFilter
Jul 30, 2019
4b4f4e2
corrected spacing for it statement
Jul 30, 2019
1db6183
Added help and direct use of % to Format-Win32NetworkADapterFilter
Jul 30, 2019
29e9ac9
Added example for wildcard use
Jul 30, 2019
de13b7c
Moved Format-Win32NetworkADapterFilterByNetConnectionID to common
Jul 30, 2019
3b4cce7
Added pester tests for Format-Win32NetworkADapterFilterByNetConnectionID
Jul 30, 2019
f66598f
Updated comment based help specifying the wildcard support
Jul 30, 2019
6324891
Added change to unreleased changelog.md
Jul 30, 2019
9e9b3c3
Updated description for interface in mof schema
Jul 30, 2019
a900bfc
Fixed test
Jul 30, 2019
3d23e04
Escaped quotes for %
Jul 30, 2019
3b35eb6
Fixed line length in changelog.md
Jul 30, 2019
c25ae74
Added - before siting bug fix
Jul 30, 2019
24b49d6
Cleaned up if statement so it would not try and replace when not nece…
Jul 30, 2019
771dcc2
Removed blank lines in changelog.md
MKletz Aug 10, 2019
8357fcc
Fixed various capitalizations
MKletz Aug 10, 2019
f8df908
removed process block
MKletz Aug 10, 2019
0ca753e
Corrected more capitalization and explictly stated a return
MKletz Aug 10, 2019
bee9163
Fixed capitalization
MKletz Aug 10, 2019
7483a30
removed extra spaces
MKletz Aug 10, 2019
abd8219
removed extra space
MKletz Aug 10, 2019
f9ce130
changed test to use single quotes
MKletz Aug 10, 2019
73cae55
corrected test it block names
MKletz Aug 10, 2019
bf9f117
Fixed style on test as well as added exactlys
MKletz Aug 10, 2019
4bfa290
Fixed outdated pester parameters
MKletz Aug 11, 2019
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
- Added Comment Based Help for `New-NotImplementedException` common
function - fixes [Issue #411](https://github.com/PowerShell/NetworkingDsc/issues/411).

- Added common function 'Format-Win32NetworkADapterFilterByNetConnectionID'
to properly accept wild cards for Win32_NetworkAdapter filters.

- Updated MSFT_Netbios to use 'Format-Win32NetworkADapterFilterByNetConnectionID'
- fixes [Issue #413](https://github.com/PowerShell/NetworkingDsc/issues/413).

## 7.3.0.0

- DnsClientGlobalSettings:
Expand Down
18 changes: 12 additions & 6 deletions DSCResources/MSFT_NetBios/MSFT_NetBios.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ catch
Returns the current state of the Net Bios on an interface.

.PARAMETER InterfaceAlias
Specifies the alias of a network interface. Supports the use of '*'.
Specifies the alias of a network interface. Supports the use of '*' and '%'.

.PARAMETER Setting
Specifies if NetBIOS should be enabled or disabled or obtained from
Expand All @@ -57,9 +57,11 @@ function Get-TargetResource

Write-Verbose -Message ($script:localizedData.GettingNetBiosSettingMessage -f $InterfaceAlias)

$Win32NetworkADapterFilter = Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $InterfaceAlias

$netAdapter = Get-CimInstance `
-ClassName Win32_NetworkAdapter `
-Filter ('NetConnectionID="{0}"' -f $InterfaceAlias)
-Filter $Win32NetworkADapterFilter

if ($netAdapter)
{
Expand Down Expand Up @@ -99,7 +101,7 @@ function Get-TargetResource
Sets the state of the Net Bios on an interface.

.PARAMETER InterfaceAlias
Specifies the alias of a network interface. Supports the use of '*'.
Specifies the alias of a network interface. Supports the use of '*' and '%'.

.PARAMETER Setting
Specifies if NetBIOS should be enabled or disabled or obtained from
Expand All @@ -122,9 +124,11 @@ function Set-TargetResource

Write-Verbose -Message ($script:localizedData.SettingNetBiosSettingMessage -f $InterfaceAlias)

$Win32NetworkADapterFilter = Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $InterfaceAlias

$netAdapter = Get-CimInstance `
-ClassName Win32_NetworkAdapter `
-Filter ('NetConnectionID="{0}"' -f $InterfaceAlias)
-Filter $Win32NetworkADapterFilter

if ($netAdapter)
{
Expand Down Expand Up @@ -177,7 +181,7 @@ function Set-TargetResource
Tests the current state the Net Bios on an interface.

.PARAMETER InterfaceAlias
Specifies the alias of a network interface. Supports the use of '*'.
Specifies the alias of a network interface. Supports the use of '*' and '%'.

.PARAMETER Setting
Specifies if NetBIOS should be enabled or disabled or obtained from
Expand All @@ -201,9 +205,11 @@ function Test-TargetResource

Write-Verbose -Message ($script:localizedData.TestingNetBiosSettingMessage -f $InterfaceAlias)

$Win32NetworkADapterFilter = Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $InterfaceAlias

$netAdapter = Get-CimInstance `
-ClassName Win32_NetworkAdapter `
-Filter ('NetConnectionID="{0}"' -f $InterfaceAlias)
-Filter $Win32NetworkADapterFilter

if ($netAdapter)
{
Expand Down
2 changes: 1 addition & 1 deletion DSCResources/MSFT_NetBios/MSFT_NetBios.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
[ClassVersion("1.0.0.0"), FriendlyName("NetBios")]
class MSFT_NetBios : OMI_BaseResource
{
[Key, Description("Specifies the alias of a network interface.")] String InterfaceAlias;
[Key, Description("Specifies the alias of a network interface. Supports the use of '*' and '%'")] String InterfaceAlias;
[Required, Description("Specifies if NetBIOS should be enabled or disabled or obtained from the DHCP server (Default). If static IP, Enable NetBIOS."), ValueMap{"Default","Enable","Disable"}, Values{"Default","Enable","Disable"}] String Setting;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<#PSScriptInfo
.VERSION 1.0.0
.GUID b43f8fac-cc5a-45ec-ab7d-344dff0b31e7
.AUTHOR Mike Kletz
.COMPANYNAME
.COPYRIGHT
.TAGS DSCConfiguration
.LICENSEURI https://github.com/PowerShell/NetworkingDsc/blob/master/LICENSE
.PROJECTURI https://github.com/PowerShell/NetworkingDsc
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES First version.
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core
#>

#Requires -module NetworkingDsc

<#
.DESCRIPTION
Disable NetBios on all adapters.
#>
Configuration NetBios_DisableNetBios_Config_Wildcard
{
Import-DscResource -ModuleName NetworkingDsc

Node localhost
{
NetBios DisableNetBios
{
InterfaceAlias = '*'
Setting = 'Disable'
}
}
}
40 changes: 39 additions & 1 deletion Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,43 @@ function ConvertTo-HashTable
}
}

<#
.SYNOPSIS
Returns a filter string for the net adapter CIM instances. Will detect wild cards and replace them and the operator accordingly.

.PARAMETER InterfaceAlias
Specifies the alias of a network interface. Supports the use of '*' or '%'.
#>
function Format-Win32NetworkADapterFilterByNetConnectionID
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$InterfaceAlias
)

process
{
if($InterfaceAlias.contains('*'))
{
$InterfaceAlias = $InterfaceAlias.replace('*','%')
}

if($InterfaceAlias.contains('%'))
{
$operator = ' LIKE '
}
else
{
$operator = '='
}

'NetConnectionID{0}"{1}"' -f $operator,$InterfaceAlias
}
}

# Import Localization Strings
$script:localizedData = Get-LocalizedData `
-ResourceName 'NetworkingDsc.Common' `
Expand All @@ -1388,5 +1425,6 @@ Export-ModuleMember -Function @(
'Test-DscParameterState',
'Test-DscObjectHasProperty'
'ConvertTo-HashTable',
'ConvertTo-CimInstance'
'ConvertTo-CimInstance',
'Format-Win32NetworkADapterFilterByNetConnectionID'
)
45 changes: 45 additions & 0 deletions Tests/Unit/NetworkingDsc.Common.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,51 @@ try
}
}
}

Describe 'NetworkingDsc.Common\Format-Win32NetworkADapterFilterByNetConnectionID'{

Context 'When interface alias has an ''*''' {

$interfaceAlias = "Ether*"

It 'Should convert the ''*'' to a ''%''' {
(Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $interfaceAlias).contains('%') -eq $True -and
(Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $interfaceAlias).contains('*') -eq $False | Should -Be $True
}

It 'Should change the operator to ''LIKE''' {
(Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $interfaceAlias) -like "NetConnectionID LIKE *" | Should -Be $True
}

It 'Looks like a usable filter' {
Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $interfaceAlias | Should -Be 'NetConnectionID LIKE "Ether%"'
}

}

Context 'When interface alias has a ''%''' {

$interfaceAlias = "Ether%"

It 'Should change the operator to ''LIKE''' {
(Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $interfaceAlias) -like "NetConnectionID LIKE *" | Should -Be $True
}

It 'Looks like a usable filter' {
Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $interfaceAlias | Should -Be 'NetConnectionID LIKE "Ether%"'
}

}

Context 'When interface alias has no wildcards' {

$interfaceAlias = "Ethernet"

It 'Looks like a usable filter' {
Format-Win32NetworkADapterFilterByNetConnectionID -InterfaceAlias $interfaceAlias | Should -Be 'NetConnectionID="Ethernet"'
}
}
}
}
}
finally
Expand Down