diff --git a/CHANGELOG.md b/CHANGELOG.md index 47fe5f28..2437a936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/source/DSCResources/DSC_DnsConnectionSuffix/DSC_DnsConnectionSuffix.psm1 b/source/DSCResources/DSC_DnsConnectionSuffix/DSC_DnsConnectionSuffix.psm1 index cb6aad4f..f89526b2 100644 --- a/source/DSCResources/DSC_DnsConnectionSuffix/DSC_DnsConnectionSuffix.psm1 +++ b/source/DSCResources/DSC_DnsConnectionSuffix/DSC_DnsConnectionSuffix.psm1 @@ -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 diff --git a/source/DSCResources/DSC_FirewallProfile/DSC_FirewallProfile.psm1 b/source/DSCResources/DSC_FirewallProfile/DSC_FirewallProfile.psm1 index 9e0a3c79..1a05d3a9 100644 --- a/source/DSCResources/DSC_FirewallProfile/DSC_FirewallProfile.psm1 +++ b/source/DSCResources/DSC_FirewallProfile/DSC_FirewallProfile.psm1 @@ -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. @@ -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. @@ -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 diff --git a/source/DSCResources/DSC_IPAddress/DSC_IPAddress.psm1 b/source/DSCResources/DSC_IPAddress/DSC_IPAddress.psm1 index a715f64c..18bd8dc1 100644 --- a/source/DSCResources/DSC_IPAddress/DSC_IPAddress.psm1 +++ b/source/DSCResources/DSC_IPAddress/DSC_IPAddress.psm1 @@ -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] { @@ -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) { @@ -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) @@ -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) diff --git a/source/DSCResources/DSC_IPAddressOption/DSC_IPAddressOption.psm1 b/source/DSCResources/DSC_IPAddressOption/DSC_IPAddressOption.psm1 index 8c90074e..06203372 100644 --- a/source/DSCResources/DSC_IPAddressOption/DSC_IPAddressOption.psm1 +++ b/source/DSCResources/DSC_IPAddressOption/DSC_IPAddressOption.psm1 @@ -83,7 +83,9 @@ function Set-TargetResource if ($currentConfig.SkipAsSource -ne $SkipAsSource) { - Set-NetIPAddress -IPAddress $IPAddress -SkipAsSource $SkipAsSource + Set-NetIPAddress ` + -IPAddress $IPAddress ` + -SkipAsSource $SkipAsSource } } diff --git a/source/DSCResources/DSC_NetAdapterLso/DSC_NetAdapterLso.psm1 b/source/DSCResources/DSC_NetAdapterLso/DSC_NetAdapterLso.psm1 index 839e2d38..c8feece8 100644 --- a/source/DSCResources/DSC_NetAdapterLso/DSC_NetAdapterLso.psm1 +++ b/source/DSCResources/DSC_NetAdapterLso/DSC_NetAdapterLso.psm1 @@ -50,7 +50,9 @@ function Get-TargetResource try { - $netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterLso ` + -Name $Name ` + -ErrorAction Stop } catch { @@ -131,7 +133,9 @@ function Set-TargetResource try { - $netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterLso ` + -Name $Name ` + -ErrorAction Stop } catch { @@ -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) { @@ -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) { @@ -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 } } } @@ -219,7 +229,9 @@ function Test-TargetResource try { - $netAdapter = Get-NetAdapterLso -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterLso ` + -Name $Name ` + -ErrorAction Stop } catch { diff --git a/source/DSCResources/DSC_NetAdapterName/DSC_NetAdapterName.psm1 b/source/DSCResources/DSC_NetAdapterName/DSC_NetAdapterName.psm1 index cb61f390..bab3ad79 100644 --- a/source/DSCResources/DSC_NetAdapterName/DSC_NetAdapterName.psm1 +++ b/source/DSCResources/DSC_NetAdapterName/DSC_NetAdapterName.psm1 @@ -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) diff --git a/source/DSCResources/DSC_NetAdapterRdma/DSC_NetAdapterRdma.psm1 b/source/DSCResources/DSC_NetAdapterRdma/DSC_NetAdapterRdma.psm1 index 26d4c3c1..bde6e762 100644 --- a/source/DSCResources/DSC_NetAdapterRdma/DSC_NetAdapterRdma.psm1 +++ b/source/DSCResources/DSC_NetAdapterRdma/DSC_NetAdapterRdma.psm1 @@ -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 { @@ -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 { @@ -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 } } } @@ -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 { diff --git a/source/DSCResources/DSC_NetAdapterRsc/DSC_NetAdapterRsc.psm1 b/source/DSCResources/DSC_NetAdapterRsc/DSC_NetAdapterRsc.psm1 index 4246dc61..3bb5e429 100644 --- a/source/DSCResources/DSC_NetAdapterRsc/DSC_NetAdapterRsc.psm1 +++ b/source/DSCResources/DSC_NetAdapterRsc/DSC_NetAdapterRsc.psm1 @@ -50,7 +50,9 @@ function Get-TargetResource try { - $netAdapter = Get-NetAdapterRsc -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterRsc ` + -Name $Name ` + -ErrorAction Stop } catch { @@ -132,7 +134,9 @@ function Set-TargetResource try { - $netAdapter = Get-NetAdapterRsc -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterRsc ` + -Name $Name ` + -ErrorAction Stop } catch { @@ -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) { @@ -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 } } } @@ -210,7 +218,9 @@ function Test-TargetResource try { - $netAdapter = Get-NetAdapterRsc -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterRsc ` + -Name $Name ` + -ErrorAction Stop } catch { diff --git a/source/DSCResources/DSC_NetAdapterRss/DSC_NetAdapterRss.psm1 b/source/DSCResources/DSC_NetAdapterRss/DSC_NetAdapterRss.psm1 index 09b43f9d..3e5508c0 100644 --- a/source/DSCResources/DSC_NetAdapterRss/DSC_NetAdapterRss.psm1 +++ b/source/DSCResources/DSC_NetAdapterRss/DSC_NetAdapterRss.psm1 @@ -42,7 +42,9 @@ function Get-TargetResource try { - $netAdapter = Get-NetAdapterRss -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterRss ` + -Name $Name ` + -ErrorAction Stop } catch { @@ -97,7 +99,9 @@ function Set-TargetResource try { - $netAdapter = Get-NetAdapterRss -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterRss ` + -Name $Name ` + -ErrorAction Stop } catch { @@ -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 } } } @@ -157,7 +163,9 @@ function Test-TargetResource try { - $netAdapter = Get-NetAdapterRss -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapterRss ` + -Name $Name ` + -ErrorAction Stop } catch { diff --git a/source/DSCResources/DSC_NetAdapterState/DSC_NetAdapterState.psm1 b/source/DSCResources/DSC_NetAdapterState/DSC_NetAdapterState.psm1 index 1f14ea7a..793801e7 100644 --- a/source/DSCResources/DSC_NetAdapterState/DSC_NetAdapterState.psm1 +++ b/source/DSCResources/DSC_NetAdapterState/DSC_NetAdapterState.psm1 @@ -44,7 +44,9 @@ function Get-TargetResource try { - $netAdapter = Get-NetAdapter -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapter ` + -Name $Name ` + -ErrorAction Stop } catch { @@ -115,7 +117,9 @@ function Set-TargetResource try { - $netAdapter = Get-NetAdapter -Name $Name -ErrorAction Stop + $netAdapter = Get-NetAdapter ` + -Name $Name ` + -ErrorAction Stop } catch { @@ -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 diff --git a/source/DSCResources/DSC_NetBios/DSC_NetBios.psm1 b/source/DSCResources/DSC_NetBios/DSC_NetBios.psm1 index 5516aa0d..a0966063 100644 --- a/source/DSCResources/DSC_NetBios/DSC_NetBios.psm1 +++ b/source/DSCResources/DSC_NetBios/DSC_NetBios.psm1 @@ -92,7 +92,9 @@ function Get-TargetResource foreach ($netAdapterItem in $netAdapter) { - $settingResults += Get-NetAdapterNetbiosOptionsFromRegistry -NetworkAdapterGUID $netAdapterItem.GUID -Setting $Setting + $settingResults += Get-NetAdapterNetbiosOptionsFromRegistry ` + -NetworkAdapterGUID $netAdapterItem.GUID ` + -Setting $Setting Write-Verbose -Message ($script:localizedData.CurrentNetBiosSettingMessage -f $netAdapterItem.NetConnectionID, $settingResults[-1]) } @@ -108,7 +110,9 @@ function Get-TargetResource } else { - $Setting = Get-NetAdapterNetbiosOptionsFromRegistry -NetworkAdapterGUID $netAdapter.GUID -Setting $Setting + $Setting = Get-NetAdapterNetbiosOptionsFromRegistry ` + -NetworkAdapterGUID $netAdapter.GUID ` + -Setting $Setting } Write-Verbose -Message ($script:localizedData.CurrentNetBiosSettingMessage -f $InterfaceAlias, $Setting) @@ -167,7 +171,9 @@ function Set-TargetResource { foreach ($netAdapterItem in $netAdapter) { - $currentValue = Get-NetAdapterNetbiosOptionsFromRegistry -NetworkAdapterGUID $netAdapterItem.GUID -Setting $Setting + $currentValue = Get-NetAdapterNetbiosOptionsFromRegistry ` + -NetworkAdapterGUID $netAdapterItem.GUID ` + -Setting $Setting # Only make changes if necessary if ($currentValue -ne $Setting) @@ -178,9 +184,10 @@ function Set-TargetResource -ResultClassName Win32_NetworkAdapterConfiguration ` -ErrorAction Stop - Set-NetAdapterNetbiosOptions -NetworkAdapterObject $netAdapterConfig ` - -InterfaceAlias $netAdapterItem.NetConnectionID ` - -Setting $Setting + Set-NetAdapterNetbiosOptions ` + -NetworkAdapterObject $netAdapterConfig ` + -InterfaceAlias $netAdapterItem.NetConnectionID ` + -Setting $Setting } } } @@ -192,9 +199,10 @@ function Set-TargetResource -ResultClassName Win32_NetworkAdapterConfiguration ` -ErrorAction Stop - Set-NetAdapterNetbiosOptions -NetworkAdapterObject $netAdapterConfig ` - -InterfaceAlias $netAdapter.NetConnectionID ` - -Setting $Setting + Set-NetAdapterNetbiosOptions ` + -NetworkAdapterObject $netAdapterConfig ` + -InterfaceAlias $netAdapter.NetConnectionID ` + -Setting $Setting } } @@ -269,8 +277,9 @@ function Get-NetAdapterNetbiosOptionsFromRegistry $currentErrorActionPreference = $ErrorActionPreference $ErrorActionPreference = 'SilentlyContinue' - $registryNetbiosOptions = Get-ItemPropertyValue -Name 'NetbiosOptions' ` - -Path "$($script:hklmInterfacesPath)\Tcpip_$($NetworkAdapterGUID)" + $registryNetbiosOptions = Get-ItemPropertyValue ` + -Name 'NetbiosOptions' ` + -Path "$($script:hklmInterfacesPath)\Tcpip_$($NetworkAdapterGUID)" $ErrorActionPreference = $currentErrorActionPreference diff --git a/source/DSCResources/DSC_NetBios/DSC_NetBios.schema.mof b/source/DSCResources/DSC_NetBios/DSC_NetBios.schema.mof index c4560067..9574a7ff 100644 --- a/source/DSCResources/DSC_NetBios/DSC_NetBios.schema.mof +++ b/source/DSCResources/DSC_NetBios/DSC_NetBios.schema.mof @@ -1,4 +1,3 @@ - [ClassVersion("1.0.0.0"), FriendlyName("NetBios")] class DSC_NetBios : OMI_BaseResource { diff --git a/source/DSCResources/DSC_NetConnectionProfile/DSC_NetConnectionProfile.psm1 b/source/DSCResources/DSC_NetConnectionProfile/DSC_NetConnectionProfile.psm1 index 9f9144aa..cef402d1 100644 --- a/source/DSCResources/DSC_NetConnectionProfile/DSC_NetConnectionProfile.psm1 +++ b/source/DSCResources/DSC_NetConnectionProfile/DSC_NetConnectionProfile.psm1 @@ -32,7 +32,8 @@ function Get-TargetResource $($script:localizedData.GettingNetConnectionProfile) -f $InterfaceAlias ) -join '') - $result = Get-NetConnectionProfile -InterfaceAlias $InterfaceAlias + $result = Get-NetConnectionProfile ` + -InterfaceAlias $InterfaceAlias return @{ InterfaceAlias = $result.InterfaceAlias @@ -136,7 +137,8 @@ function Test-TargetResource Assert-ResourceProperty @PSBoundParameters - $current = Get-TargetResource -InterfaceAlias $InterfaceAlias + $current = Get-TargetResource ` + -InterfaceAlias $InterfaceAlias if (-not [System.String]::IsNullOrEmpty($IPv4Connectivity) -and ` ($IPv4Connectivity -ne $current.IPv4Connectivity)) diff --git a/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1 b/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1 index 5cb3caad..6ed8ba67 100644 --- a/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1 +++ b/source/DSCResources/DSC_NetIPInterface/DSC_NetIPInterface.psm1 @@ -484,7 +484,8 @@ function Get-NetworkIPInterface $($script:localizedData.GettingNetIPInterfaceMessage) -f $InterfaceAlias, $AddressFamily ) -join '') - $netIPInterface = Get-NetIPInterface @PSBoundParameters -ErrorAction SilentlyContinue + $netIPInterface = Get-NetIPInterface @PSBoundParameters ` + -ErrorAction SilentlyContinue if (-not $netIPInterface) { diff --git a/source/DSCResources/DSC_NetworkTeam/DSC_NetworkTeam.psm1 b/source/DSCResources/DSC_NetworkTeam/DSC_NetworkTeam.psm1 index c533558c..a33653ff 100644 --- a/source/DSCResources/DSC_NetworkTeam/DSC_NetworkTeam.psm1 +++ b/source/DSCResources/DSC_NetworkTeam/DSC_NetworkTeam.psm1 @@ -43,7 +43,9 @@ function Get-TargetResource } Write-Verbose -Message ($script:localizedData.GetTeamInfo -f $Name) - $networkTeam = Get-NetLBFOTeam -Name $Name -ErrorAction SilentlyContinue + $networkTeam = Get-NetLBFOTeam ` + -Name $Name ` + -ErrorAction SilentlyContinue if ($networkTeam) { @@ -121,7 +123,9 @@ function Set-TargetResource Write-Verbose -Message ($script:localizedData.GetTeamInfo -f $Name) - $networkTeam = Get-NetLBFOTeam -Name $Name -ErrorAction SilentlyContinue + $networkTeam = Get-NetLBFOTeam ` + -Name $Name ` + -ErrorAction SilentlyContinue if ($Ensure -eq 'Present') { @@ -153,7 +157,9 @@ function Set-TargetResource { Write-Verbose -Message ($script:localizedData.ModifyTeam -f $Name) - Set-NetLbfoTeam @setArguments -ErrorAction Stop -Confirm:$false + Set-NetLbfoTeam @setArguments ` + -ErrorAction Stop ` + -Confirm:$false } $netTeamMembers = Compare-Object ` @@ -172,7 +178,8 @@ function Set-TargetResource { Write-Verbose -Message ($script:localizedData.RemovingMembers -f ($membersToRemove -join ',')) - $null = Remove-NetLbfoTeamMember -Name $membersToRemove ` + $null = Remove-NetLbfoTeamMember ` + -Name $membersToRemove ` -Team $Name ` -ErrorAction Stop ` -Confirm:$false @@ -186,7 +193,8 @@ function Set-TargetResource { Write-Verbose -Message ($script:localizedData.AddingMembers -f ($membersToAdd -join ',')) - $null = Add-NetLbfoTeamMember -Name $membersToAdd ` + $null = Add-NetLbfoTeamMember ` + -Name $membersToAdd ` -Team $Name ` -ErrorAction Stop ` -Confirm:$false @@ -221,7 +229,10 @@ function Set-TargetResource { Write-Verbose -Message ($script:localizedData.RemoveTeam -f $Name) - $null = Remove-NetLbfoTeam -Name $name -ErrorAction Stop -Confirm:$false + $null = Remove-NetLbfoTeam ` + -Name $name ` + -ErrorAction Stop ` + -Confirm:$false } } @@ -277,7 +288,9 @@ function Test-TargetResource Write-Verbose -Message ($script:localizedData.GetTeamInfo -f $Name) - $networkTeam = Get-NetLbfoTeam -Name $Name -ErrorAction SilentlyContinue + $networkTeam = Get-NetLbfoTeam ` + -Name $Name ` + -ErrorAction SilentlyContinue if ($ensure -eq 'Present') { diff --git a/source/DSCResources/DSC_NetworkTeamInterface/DSC_NetworkTeamInterface.schema.mof b/source/DSCResources/DSC_NetworkTeamInterface/DSC_NetworkTeamInterface.schema.mof index b7b36416..a4dc056d 100644 --- a/source/DSCResources/DSC_NetworkTeamInterface/DSC_NetworkTeamInterface.schema.mof +++ b/source/DSCResources/DSC_NetworkTeamInterface/DSC_NetworkTeamInterface.schema.mof @@ -1,4 +1,3 @@ - [ClassVersion("1.0"), FriendlyName("NetworkTeamInterface")] class DSC_NetworkTeamInterface : OMI_BaseResource { diff --git a/source/DSCResources/DSC_ProxySettings/DSC_ProxySettings.psm1 b/source/DSCResources/DSC_ProxySettings/DSC_ProxySettings.psm1 index a9472a81..9541a380 100644 --- a/source/DSCResources/DSC_ProxySettings/DSC_ProxySettings.psm1 +++ b/source/DSCResources/DSC_ProxySettings/DSC_ProxySettings.psm1 @@ -60,7 +60,8 @@ function Get-TargetResource { $returnValue.Add('Ensure','Present') - $proxySettings = ConvertFrom-ProxySettingsBinary -ProxySettings $proxySettingsRegistryBinary + $proxySettings = ConvertFrom-ProxySettingsBinary ` + -ProxySettings $proxySettingsRegistryBinary $returnValue.Add('EnableManualProxy',$proxySettings.EnableManualProxy) $returnValue.Add('EnableAutoConfiguration',$proxySettings.EnableAutoConfiguration) @@ -392,14 +393,17 @@ function Test-TargetResource if ($connectionsRegistryValues.DefaultConnectionSettings) { - $defaultConnectionSettings = ConvertFrom-ProxySettingsBinary -ProxySettings $connectionsRegistryValues.DefaultConnectionSettings + $defaultConnectionSettings = ConvertFrom-ProxySettingsBinary ` + -ProxySettings $connectionsRegistryValues.DefaultConnectionSettings } else { $defaultConnectionSettings = @{} } - $inDesiredState = Test-ProxySettings -CurrentValues $defaultConnectionSettings -DesiredValues $desiredValues + $inDesiredState = Test-ProxySettings ` + -CurrentValues $defaultConnectionSettings ` + -DesiredValues $desiredValues if (-not $inDesiredState) { @@ -420,14 +424,17 @@ function Test-TargetResource if ($connectionsRegistryValues.SavedLegacySettings) { - $savedLegacySettings = ConvertFrom-ProxySettingsBinary -ProxySettings $connectionsRegistryValues.SavedLegacySettings + $savedLegacySettings = ConvertFrom-ProxySettingsBinary ` + -ProxySettings $connectionsRegistryValues.SavedLegacySettings } else { $savedLegacySettings = @{} } - $inDesiredState = Test-ProxySettings -CurrentValues $savedLegacySettings -DesiredValues $desiredValues + $inDesiredState = Test-ProxySettings ` + -CurrentValues $savedLegacySettings ` + -DesiredValues $desiredValues if (-not $inDesiredState) { @@ -792,7 +799,9 @@ function ConvertFrom-ProxySettingsBinary # Extract the Proxy Server string $proxyServer = '' - $stringLength = Get-Int32FromByteArray -Byte $ProxySettings -StartByte $stringPointer + $stringLength = Get-Int32FromByteArray ` + -Byte $ProxySettings ` + -StartByte $stringPointer $stringPointer += 4 if ($stringLength -gt 0) @@ -807,7 +816,9 @@ function ConvertFrom-ProxySettingsBinary # Extract the Proxy Server Exceptions string $proxyServerExceptions = @() - $stringLength = Get-Int32FromByteArray -Byte $ProxySettings -StartByte $stringPointer + $stringLength = Get-Int32FromByteArray ` + -Byte $ProxySettings ` + -StartByte $stringPointer $stringPointer += 4 if ($stringLength -gt 0) diff --git a/source/DSCResources/DSC_WaitForNetworkTeam/DSC_WaitForNetworkTeam.schema.mof b/source/DSCResources/DSC_WaitForNetworkTeam/DSC_WaitForNetworkTeam.schema.mof index 3034cf9a..bded4b01 100644 --- a/source/DSCResources/DSC_WaitForNetworkTeam/DSC_WaitForNetworkTeam.schema.mof +++ b/source/DSCResources/DSC_WaitForNetworkTeam/DSC_WaitForNetworkTeam.schema.mof @@ -1,4 +1,3 @@ - [ClassVersion("1.0.0.0"), FriendlyName("WaitForNetworkTeam")] class DSC_WaitForNetworkTeam : OMI_BaseResource { diff --git a/source/DSCResources/DSC_WinsServerAddress/DSC_WinsServerAddress.psm1 b/source/DSCResources/DSC_WinsServerAddress/DSC_WinsServerAddress.psm1 index e8598e34..6951523d 100644 --- a/source/DSCResources/DSC_WinsServerAddress/DSC_WinsServerAddress.psm1 +++ b/source/DSCResources/DSC_WinsServerAddress/DSC_WinsServerAddress.psm1 @@ -77,7 +77,10 @@ function Set-TargetResource Write-Verbose -Message "$($MyInvocation.MyCommand): $($script:localizedData.ApplyingWinsServerAddressesMessage)" - Set-WinsClientServerStaticAddress -InterfaceAlias $InterfaceAlias -Address $Address -ErrorAction Stop + Set-WinsClientServerStaticAddress ` + -InterfaceAlias $InterfaceAlias ` + -Address $Address ` + -ErrorAction Stop } diff --git a/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 new file mode 100644 index 00000000..c775e300 --- /dev/null +++ b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 @@ -0,0 +1,161 @@ +$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' + +# Import the Networking Common Modules +Import-Module -Name (Join-Path -Path $modulePath ` + -ChildPath (Join-Path -Path 'NetworkingDsc.Common' ` + -ChildPath 'NetworkingDsc.Common.psm1')) + +Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common') + +# Import Localization Strings +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' + +<# + .SYNOPSIS + Gets the power management state of the network adapter. + + .PARAMETER Name + Specifies the name of the network adapter. +#> +function Get-TargetResource { + [CmdletBinding()] + [OutputType([Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [ValidateSet('Enabled', 'Disabled')] + [System.String] + $State + ) + + Write-Verbose "Getting the power setting on the network adpater." + + $nic = Get-NetAdapterPowerManagement ` + -Name $Name ` + -IncludeHidden:$true + + if ($nic.DeviceSleepOnDisconnect -eq 'Inactive') { + $State = 'Disabled' + } + else { + $State = 'Enabled' + } + + return @{ + Name = $Name + State = $State + } +} + +<# + .SYNOPSIS + Sets the power management properties on the network adapter. + + .PARAMETER Name + Specifies the name of the network adapter. + + .PARAMETER State + Allows to set the state of the Network Adapter power management settings to disable to enable. + + .PARAMETER NoRestart + Specifies whether to restart the network adapter after changing the power management setting. +#> +function Set-TargetResource { + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [ValidateSet('Enabled', 'Disabled')] + [System.String] + $State, + + [Parameter()] + [System.Boolean] + $NoRestart = $false + ) + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $script:localizedData.CheckingNetAdapterMessage + ) -join '') + + $PSBoundParameters.Remove("NoRestart") + $currentState = Get-TargetResource @PSBoundParameters + + if ($currentState.State -eq 'Disabled') + { + if ($State -eq 'Enabled') + { + Enable-NetAdapterPowerManagement ` + -Name $Name ` + -IncludeHidden:$true ` + -NoRestart:$NoRestart + } + } else { + if ($State -eq 'Disabled') + { + Disable-NetAdapterPowerManagement ` + -Name $Name ` + -IncludeHidden:$true ` + -NoRestart:$NoRestart + } + } +} + +<# + .SYNOPSIS + Tests if the power management state of the network adapter is in the desired state. + + .PARAMETER Name + Specifies the name of the network adapter. + + .PARAMETER State + Allows to Check the state of the Network Adapter power management settings to disable to enable to see if it needs to be changed. +#> +function Test-TargetResource { + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [ValidateSet('Enabled', 'Disabled')] + [System.String] + $State + ) + + Write-Verbose "Checking to see if the power setting on the NIC for $Name." + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($script:localizedData.NetPowerManagementMessage -f $Name) + ) -join '') + + $currentState = Get-TargetResource @PSBoundParameters + + if ($currentState) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($script:localizedData.NetPowerManagementMessage -f $Name, $currentState.State) + ) -join '') + + return $currentState.State -eq $State + } + + return $false +} + + +Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof new file mode 100644 index 00000000..72cfd4c3 --- /dev/null +++ b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof @@ -0,0 +1,6 @@ +[ClassVersion("1.0.0.0"), FriendlyName("MSFT_xNetPowerManagement")] +class MSFT_xNetPowerManagement : OMI_BaseResource +{ + [Key, Description("Specifies the adapter Type you want to effect. Example 'Ethernet 802.3' for Ethernet adapters")] String AdapterType; + [Write, Description("Specifies to Enable or Disable the power management feature of the NIC."), ValueMap{"Enabled","Disabled"}, Values{"Enabled","Disabled"}] String State; +}; diff --git a/source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1 b/source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1 index 189754ce..0b71bc8e 100644 --- a/source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1 +++ b/source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1 @@ -396,7 +396,9 @@ function Get-WinsClientServerStaticAddress Write-Verbose -Message ("$($MyInvocation.MyCommand): $($script:localizedData.GettingWinsServerStaticAddressMessage -f $InterfaceAlias)") # Look up the interface Guid - $adapter = Get-NetAdapter -InterfaceAlias $InterfaceAlias -ErrorAction SilentlyContinue + $adapter = Get-NetAdapter ` + -InterfaceAlias $InterfaceAlias ` + -ErrorAction SilentlyContinue if (-not $adapter) { @@ -458,7 +460,9 @@ function Set-WinsClientServerStaticAddress Write-Verbose -Message ("$($MyInvocation.MyCommand): $($script:localizedData.SettingWinsServerStaticAddressMessage -f $InterfaceAlias, ($Address -join ', '))") # Look up the interface Guid - $adapter = Get-NetAdapter -InterfaceAlias $InterfaceAlias -ErrorAction SilentlyContinue + $adapter = Get-NetAdapter ` + -InterfaceAlias $InterfaceAlias ` + -ErrorAction SilentlyContinue if (-not $adapter) { diff --git a/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 b/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 new file mode 100644 index 00000000..939d95de --- /dev/null +++ b/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 @@ -0,0 +1,98 @@ +$script:DSCModuleName = 'xNetworking' +$script:DSCResourceName = 'MSFT_xNetPowerManagement' + +#region HEADER +# Unit Test Template Version: 1.1.0 +[string] $script:moduleRoot = Join-Path -Path $(Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))) -ChildPath 'Modules\xNetworking' +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` + -TestType Unit +#endregion HEADER + +# Begin Testing +try +{ + #region Pester Tests + InModuleScope $script:DSCResourceName { + + Describe "MSFT_xNetPowerManagement\Get-TargetResource" { + Mock Get-NetPowerManagement { + return @{ + AdapterType = 'Ethernet 802.3' + State = $true + } + } + $expected = @() + $expected.AdpaterType = 'Ethernet 802.3' + $expected.State = $true + + $result = Get-TargetResource -InterfaceAlias $expected.InterfaceAlias + + It 'Should return the correct values' { + $expected.AdpaterType | Should Be $result.AdapterType + $expected.State | Should Be $result.State + } + } + + Describe "MSFT_xNetPowerManagement\Test-TargetResource" { + $Splat = @{ + AdapterType = 'Ethernet 802.3' + State = $true + } + + Context 'AdapterType is incorrect' { + $incorrect = $Splat.Clone() + $incorrect.AdapterType = 'Ethernet 802.3' + Mock Get-TargetResource { + return $incorrect + } + + It 'should return Ethernet 802.3' { + Test-TargetResource @Splat | should be 'Ethernet 802.3' + } + } + + Context 'State is incorrect' { + $incorrect = $Splat.Clone() + $incorrect.State = $false + Mock Get-TargetResource { + return $incorrect + } + + It 'should return true' { + Test-TargetResource @Splat | should be $true + } + } + + Describe "MSFT_xNetPowerManagement\Set-TargetResource" { + It 'Should do call all the mocks' { + $Splat = @{ + $incorrect = $Splat.Clone() + $incorrect.AdapterType = 'Ethernet 802.3' + } + +?????? Mock Set-NetConnectionProfile {} + + Set-TargetResource @Splat + + Assert-MockCalled Set-NetConnectionProfile + } + } + } #end InModuleScope $DSCResourceName + #endregion + } +} +finally +{ + #region FOOTER + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion +}