From f8c2dcd3e48497d6c93243810caa96a86cd1b332 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 19 May 2021 17:58:39 -0400 Subject: [PATCH 01/15] Clean spurious newline at file beginning --- source/DSCResources/DSC_NetBios/DSC_NetBios.schema.mof | 1 - .../DSC_NetworkTeamInterface/DSC_NetworkTeamInterface.schema.mof | 1 - .../DSC_WaitForNetworkTeam/DSC_WaitForNetworkTeam.schema.mof | 1 - 3 files changed, 3 deletions(-) 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_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_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 { From e98d1aa7994204962ef0fe97aade744dcf498f25 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 19 May 2021 21:37:44 -0400 Subject: [PATCH 02/15] Reformat whitespace for diffability to match other modues --- .../DSC_DnsConnectionSuffix.psm1 | 4 ++- .../DSC_FirewallProfile.psm1 | 9 ++++-- .../DSC_IPAddress/DSC_IPAddress.psm1 | 14 ++++++--- .../DSC_IPAddressOption.psm1 | 4 ++- .../DSC_NetAdapterLso/DSC_NetAdapterLso.psm1 | 24 ++++++++++---- .../DSC_NetAdapterName.psm1 | 3 +- .../DSC_NetAdapterRdma.psm1 | 16 +++++++--- .../DSC_NetAdapterRsc/DSC_NetAdapterRsc.psm1 | 20 +++++++++--- .../DSC_NetAdapterRss/DSC_NetAdapterRss.psm1 | 16 +++++++--- .../DSC_NetAdapterState.psm1 | 17 +++++++--- .../DSCResources/DSC_NetBios/DSC_NetBios.psm1 | 31 ++++++++++++------- .../DSC_NetConnectionProfile.psm1 | 6 ++-- .../DSC_NetIPInterface.psm1 | 3 +- .../DSC_NetworkTeam/DSC_NetworkTeam.psm1 | 27 +++++++++++----- .../DSC_ProxySettings/DSC_ProxySettings.psm1 | 25 ++++++++++----- .../DSC_WinsServerAddress.psm1 | 5 ++- .../NetworkingDsc.Common.psm1 | 8 +++-- 17 files changed, 168 insertions(+), 64 deletions(-) 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_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_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_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/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) { From 0572312b2882b42f872db7abb3cec082deb562f9 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 19 May 2021 22:54:55 -0400 Subject: [PATCH 03/15] Minor code style reformatting. Minor reformatting of code style. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47fe5f28..ca6e7ead 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). +- Minor reformatting of code style for diffability. ## [8.2.0] - 2020-10-16 From a153e23b9c525905064f8159b4e92c40499b04d2 Mon Sep 17 00:00:00 2001 From: edycus Date: Thu, 9 Mar 2017 13:35:49 -0800 Subject: [PATCH 04/15] Test Create File --- Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a | 1 + 1 file changed, 1 insertion(+) create mode 100644 Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a new file mode 100644 index 00000000..78981922 --- /dev/null +++ b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a @@ -0,0 +1 @@ +a From 5ffe7a1aa33f532d3c532bf9a3c674bd4b88fc4e Mon Sep 17 00:00:00 2001 From: edycus Date: Thu, 9 Mar 2017 13:40:24 -0800 Subject: [PATCH 05/15] Add repository for power management of the network adapter --- .../MSFT_xNetPowerManagement.psm1 | Bin 0 -> 8188 bytes .../MSFT_xNetPowerManagement.schema.mof | Bin 0 -> 884 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 create mode 100644 Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.schema.mof diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 new file mode 100644 index 0000000000000000000000000000000000000000..2bd3d905174dd5268d77e0674c623fd1dc00ccbe GIT binary patch literal 8188 zcmeHMU2oeq6uqw=(EmUz29gZ5F|03pXosa~x&>I=AWmBhSrFKR*HW7mZU6eV zb9jACN|xk&xPylUhAfIAdA~0Yum1k)v8>4h`AXdM*Oa#WDlK^-`)KXrir*ecUs8D| z6B$Z^8L7NMkCRj1H$i)dK8JUyba3(ANY3!z!PWA!uh27*Kk&Sd))o3DXzyXf5Z5`L zFL805rl%d#Z(`1t9N^lM9XZ5xfVo@J!_2X#H$m?QwEG#p+rH;i2H<6YcQNmzN{Ys* z$uvY?3jU1SPKF9)S2_;&5#)CmOBpDCiXLj^jqjmMO+5GIPfu$s7oOfa_*ZJwC#gC4 zUcQy@F#3_K&!k_IA7M@uPqB@H_?|BX8LRbX2Y;IH>0M87OwK;`t4@y_!kv zKsn4O%_6R^yzJ`Vv(duT_|bFeYsRl-o;rF5kV)-oUi}(U50H(z@;j*0!yK%@ z6&@i@PI5UVYfmSiFq$0EhiIdZu=xonXUCauJ859lTZ~&2nV&O$QHMP&lkGvWOV1^} zvr39R_-M$0CqnDI_ZsLUFEA^q-pEx8Ps~w?j}1n&^SY%re}jb7QMt6cSWPoBGe>{6 zS`$${g4d4m(?|7p&%x;hHD)xjeMBatZeQGD79!8>KAjO7B6tRj04PoW+VAfN)%UM=+ z$Z+%c&}i9?5_lkJ0o{=PY9XJ8GXzlsXGg#| z%&i0L{EFsPCmTQ-@eb9)^Fv(EGFoSEK$F+UWLZy(aaf##Y)_)i7wxoP9xs$3NzHv0 zS&EnX&?Qd>F4|cY1rp6F21=&r(`J_KVIe~P&$z?1l)uORV($Vj34RvizPt~w!xF{X zw-u|;1o3*d(}(;=JaF?omq*UViQTV*x$@Y_Arl?~tMeqPCt;r2_h%Wn=zQ*g@#xKp zgR=O`cv*zQY+SV#L$+Bx9U5xPYmj8<*n63bXH%XhZ8Te*2jPP z9II=6pqPLVyM9buq3aSjLdo)^X?F}x`43mai!KHxv#TI z$5ZvO$Fsz;apiz{EXI|VO{@2y5D8%qvhz;xH;a*g%<`uc?ylS$Y@}8NxR=`JFndC>x|QL9IBREXm8)6#i}^L=y9#LjzWTSk>fc>acEIZ)qU@|wUPnAbcGQ~S z-O#(mX25a9U#jL~T$Vz&TT!C-yvdNjYGRv??ZRB zRhf-~{A!`w`RXDYRafQz9SxLw>utQUIyz%J2cOKwImd)|eA>a6VtUsEQPse=&k;P5 gC$m1MLbrnTdI9}$_ZGUZiOgJ2({YijO5wE9-&M+4L}ciSGrHt@BNpf}U>V+A3uvA>I`Flg z0oA5A_nZmum?}fBm*Z(r3y;jX6y;X2Rn(r6WzGei;QkTVWB!L!wLa^pDwC}6G%$(W zH6=J6bY9_GvOQb+@!(ifV>8~=6Vuo7>An Date: Thu, 9 Mar 2017 13:41:32 -0800 Subject: [PATCH 06/15] Delete test file --- Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a deleted file mode 100644 index 78981922..00000000 --- a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/a +++ /dev/null @@ -1 +0,0 @@ -a From 2d558d1e0de2484c5e77b68982acc6386b8a90e1 Mon Sep 17 00:00:00 2001 From: sa-ericd Date: Mon, 10 Jul 2017 16:09:01 -0700 Subject: [PATCH 07/15] Changed to UTF and removed Tabs --- .../MSFT_xNetPowerManagement.psm1 | Bin 8188 -> 4272 bytes .../MSFT_xNetPowerManagement.schema.mof | Bin 884 -> 445 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 index 2bd3d905174dd5268d77e0674c623fd1dc00ccbe..5fe18cd0d7dbee76a86f0ca503fc464534de0a2f 100644 GIT binary patch literal 4272 zcmd^C&2HO95WXAGI}Bt2mWqfdl1mP4QO8zV0hKJ6N{qq{j1@VO*pR#I?$U~p=E-{K zBlQ(JvrCG!BwKcox(KR+Y>K-x-~4_1?O%WV`ORVL0O%8hKabBQ;V|@%=V%Kp4cH|@ zRA`OTg0aFPs5uB2qg^Te9wusq8b(5j1!lA+XdRU1CdcQ;qrr4=4#%;`E$Zn_j{aSk zW0cGj^wy=woKf~9OS8gn0ZV(}MisCUe>tyk>E0k^pi6m*g;n|nzJ-p}1+I7d zm8GZ9YC=cb12SnR(=JyQmu{f55mGBFUj;5cnDrpYxGDv@)gGvV?g zW~#6dsVpN@kZTp8G2}OBZx}wsS+Uq@cEyg#IKOY2UM&-CDlWpu&Q;KeANu&)R^dPSly`D&$k8IRTP{YS zYu2k%yiOt1r$JBi$7ZHLcn7^#DzFiL{|-;!uAb#Xqw>pt>s(aKSFsx$PDxmhikN%xP-_R6qae{yavNLO z{~{!FNGvHzj2)rQNXI(y7;iBtr})uSdbvX)zEUbhA^!_e z_=J4BV+vg%-4ycK=W@@C;n|`*)_}BlMI%J1mDB(h*|(I&zbQcd*!`a*=sw!NN2ktN zjqW)jNL+4R0xKZ{bO$MQOuThKXf#F2D&5K9nmQlA`TKlIWoy6ChxIYGc}Ue5T&N8Y z4SMEw-#kD|0dwp8+?&XzR@gB^`=VNBk|L^3y?e5{8PUdd;vWFGmDamcSzk}sN2#IQ o2}gGWu6cPaXdMhbI=AWmBhSrFKR*HW7mZU6eV zb9jACN|xk&xPylUhAfIAdA~0Yum1k)v8>4h`AXdM*Oa#WDlK^-`)KXrir*ecUs8D| z6B$Z^8L7NMkCRj1H$i)dK8JUyba3(ANY3!z!PWA!uh27*Kk&Sd))o3DXzyXf5Z5`L zFL805rl%d#Z(`1t9N^lM9XZ5xfVo@J!_2X#H$m?QwEG#p+rH;i2H<6YcQNmzN{Ys* z$uvY?3jU1SPKF9)S2_;&5#)CmOBpDCiXLj^jqjmMO+5GIPfu$s7oOfa_*ZJwC#gC4 zUcQy@F#3_K&!k_IA7M@uPqB@H_?|BX8LRbX2Y;IH>0M87OwK;`t4@y_!kv zKsn4O%_6R^yzJ`Vv(duT_|bFeYsRl-o;rF5kV)-oUi}(U50H(z@;j*0!yK%@ z6&@i@PI5UVYfmSiFq$0EhiIdZu=xonXUCauJ859lTZ~&2nV&O$QHMP&lkGvWOV1^} zvr39R_-M$0CqnDI_ZsLUFEA^q-pEx8Ps~w?j}1n&^SY%re}jb7QMt6cSWPoBGe>{6 zS`$${g4d4m(?|7p&%x;hHD)xjeMBatZeQGD79!8>KAjO7B6tRj04PoW+VAfN)%UM=+ z$Z+%c&}i9?5_lkJ0o{=PY9XJ8GXzlsXGg#| z%&i0L{EFsPCmTQ-@eb9)^Fv(EGFoSEK$F+UWLZy(aaf##Y)_)i7wxoP9xs$3NzHv0 zS&EnX&?Qd>F4|cY1rp6F21=&r(`J_KVIe~P&$z?1l)uORV($Vj34RvizPt~w!xF{X zw-u|;1o3*d(}(;=JaF?omq*UViQTV*x$@Y_Arl?~tMeqPCt;r2_h%Wn=zQ*g@#xKp zgR=O`cv*zQY+SV#L$+Bx9U5xPYmj8<*n63bXH%XhZ8Te*2jPP z9II=6pqPLVyM9buq3aSjLdo)^X?F}x`43mai!KHxv#TI z$5ZvO$Fsz;apiz{EXI|VO{@2y5D8%qvhz;xH;a*g%<`uc?ylS$Y@}8NxR=`JFndC>x|QL9IBREXm8)6#i}^L=y9#LjzWTSk>fc>acEIZ)qU@|wUPnAbcGQ~S z-O#(mX25a9U#jL~T$Vz&TT!C-yvdNjYGRv??ZRB zRhf-~{A!`w`RXDYRafQz9SxLw>utQUIyz%J2cOKwImd)|eA>a6VtUsEQPse=&k;P5 gC$m1!el#ahHt47Q+$Dtt3@c?GkGmh%}q8cE=_0hdz)^QQ@9yQY?mF zag+xJ+-iX*cuyC*S9J7APB%8EI6B1<__ckbb_7#$xs`@Hh0IVcOGys+hX4ySOcqwH zA!v022UHBKfy$C{PGEM#+EfHH-)$8!JdW>^2Pn1ud+H(1%Rgzt8A=f zx-Fw&rtsTO^5m&>-8C4R5D3)QM4%+(#`?ap`@wQCNkX1$tQtzuoWzAwh>_?yg*f+h P_kZ=OoiTC{KKt_v2tt*e literal 884 zcmb7?PfNo<5XIkB!SAs2q)@~^7txcp6+~LaNMLbrnTdI9}$_ZGUZiOgJ2({YijO5wE9-&M+4L}ciSGrHt@BNpf}U>V+A3uvA>I`Flg z0oA5A_nZmum?}fBm*Z(r3y;jX6y;X2Rn(r6WzGei;QkTVWB!L!wLa^pDwC}6G%$(W zH6=J6bY9_GvOQb+@!(ifV>8~=6Vuo7>An Date: Sat, 22 May 2021 19:55:21 -0400 Subject: [PATCH 08/15] Made changes based on testing --- .../MSFT_xNetPowerManagement.psm1 | 288 +++++++++--------- .../MSFT_xNetPowerManagement.schema.mof | 14 +- 2 files changed, 151 insertions(+), 151 deletions(-) diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 index 5fe18cd0..825876e7 100644 --- a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 +++ b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 @@ -1,144 +1,144 @@ -<# - .SYNOPSIS - Returns the current state of a Network Power Management. - - .PARAMETER AdapterType - Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' - -#> - -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [parameter(Mandatory = $true)] - [System.String] - $AdapterType - ) - - #Write-Verbose "Use this cmdlet to deliver information about command processing." - - #Write-Debug "Use this cmdlet to write debug information while troubleshooting." - $nic = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'} - $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - - If ($powerMgmt.Enable -eq $true){ - $State = $False - }ELSE{ - $State = $true - } - - - $returnValue = @{ - NICPowerSaving = $powerMgmt.Enable - AdapterType = $AdapterType - State = $State - } - - $returnValue -} - -<# - .SYNOPSIS - Sets the current state of a Network Power Management. - - .PARAMETER AdapterType - Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' - - .PARAMETER State - Allows to set the state of the Network Adapter power management settings to disable to enable. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [parameter(Mandatory = $true)] - [System.String] - $AdapterType, - - [ValidateSet("Enabled","Disabled")] - [System.String] - $State - ) - - - $nics = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq $AdapterType} - foreach ($nic in $nics) - { - $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - - If ($State -eq 'Disabled'){ - Write-Verbose "Disabling the NIC power management setting." - $powerMgmt.Enable = $False #Turn off PowerManagement feature - }ELSE{ - Write-Verbose "Enabling the NIC power management setting." - $powerMgmt.Enable = $true #Turn on PowerManagement feature - } - - $powerMgmt.psbase.Put() | Out-Null - } - - -} - -<# - .SYNOPSIS - Test the current state of a Network Power Management. - - .PARAMETER AdapterType - Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' - - .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] - $AdapterType, - - [ValidateSet("Enabled","Disabled")] - [System.String] - $State - ) - - Write-Verbose "Checking to see if the power setting on the NIC for Adapter Type $AdapterType." - - #Write-Debug "Use this cmdlet to write debug information while troubleshooting." - - $nic = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'} - $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - - If ($State -eq 'Disabled'){ - If ($powerMgmt.Enable -eq $false){ - Write-Verbose "NIC Power Management setting is disabled." - $result = $true - }ELSE{ - Write-Verbose "NIC Power Management setting is not disabled. - Disabling" - $result = $false - } - } - - If ($State -eq 'Enabled'){ - If ($powerMgmt.Enable -eq $false) { - Write-Verbose "NIC Power Management setting is disabled. - Enabling." - $result = $false - }ELSE{ - Write-Verbose "NIC Power Management setting is not disabled." - $result = $true - } - } - -$result -} - - -Export-ModuleMember -Function *-TargetResource - +<# + .SYNOPSIS + Returns the current state of a Network Power Management. + + .PARAMETER AdapterType + Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' + +#> + +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $AdapterType + ) + + #Write-Verbose "Use this cmdlet to deliver information about command processing." + + #Write-Debug "Use this cmdlet to write debug information while troubleshooting." + $nic = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'} + $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} + + If ($powerMgmt.Enable -eq $true){ + $State = $False + }ELSE{ + $State = $true + } + + + $returnValue = @{ + NICPowerSaving = $powerMgmt.Enable + AdapterType = $AdapterType + State = $State + } + + $returnValue +} + +<# + .SYNOPSIS + Sets the current state of a Network Power Management. + + .PARAMETER AdapterType + Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' + + .PARAMETER State + Allows to set the state of the Network Adapter power management settings to disable to enable. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $AdapterType, + + [ValidateSet("Enabled","Disabled")] + [System.String] + $State + ) + + + $nics = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq $AdapterType} + foreach ($nic in $nics) + { + $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} + + If ($State -eq 'Disabled'){ + Write-Verbose "Disabling the NIC power management setting." + $powerMgmt.Enable = $False #Turn off PowerManagement feature + }ELSE{ + Write-Verbose "Enabling the NIC power management setting." + $powerMgmt.Enable = $true #Turn on PowerManagement feature + } + + $powerMgmt.psbase.Put() | Out-Null + } + + +} + +<# + .SYNOPSIS + Test the current state of a Network Power Management. + + .PARAMETER AdapterType + Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' + + .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] + $AdapterType, + + [ValidateSet("Enabled","Disabled")] + [System.String] + $State + ) + + Write-Verbose "Checking to see if the power setting on the NIC for Adapter Type $AdapterType." + + #Write-Debug "Use this cmdlet to write debug information while troubleshooting." + + $nic = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'} + $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} + + If ($State -eq 'Disabled'){ + If ($powerMgmt.Enable -eq $false){ + Write-Verbose "NIC Power Management setting is disabled." + $result = $true + }ELSE{ + Write-Verbose "NIC Power Management setting is not disabled. - Disabling" + $result = $false + } + } + + If ($State -eq 'Enabled'){ + If ($powerMgmt.Enable -eq $false) { + Write-Verbose "NIC Power Management setting is disabled. - Enabling." + $result = $false + }ELSE{ + Write-Verbose "NIC Power Management setting is not disabled." + $result = $true + } + } + +$result +} + + +Export-ModuleMember -Function *-TargetResource + diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.schema.mof b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.schema.mof index a2f392ed..fd56e2b3 100644 --- a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.schema.mof +++ b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.schema.mof @@ -1,7 +1,7 @@ - -[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; -}; + +[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; +}; From b52fe0bc8b3af32c5f2628794df187d48dbcac87 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 22 May 2021 19:55:36 -0400 Subject: [PATCH 09/15] Made changes based on testing --- .../MSFT_xNetPowerManagement.psm1 | 14 +-- tests/Unit/MSFT_xNetPowerManagement.tests.ps1 | 97 +++++++++++++++++++ 2 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 tests/Unit/MSFT_xNetPowerManagement.tests.ps1 diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 index 825876e7..9a9fb332 100644 --- a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 +++ b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 @@ -18,11 +18,11 @@ function Get-TargetResource $AdapterType ) - #Write-Verbose "Use this cmdlet to deliver information about command processing." + Write-Verbose "Getting the power setting on the network adpater." #Write-Debug "Use this cmdlet to write debug information while troubleshooting." - $nic = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'} - $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} + $nic = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq 'Ethernet 802.3'} + $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} If ($powerMgmt.Enable -eq $true){ $State = $False @@ -65,10 +65,10 @@ function Set-TargetResource ) - $nics = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq $AdapterType} + $nics = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq $AdapterType} foreach ($nic in $nics) { - $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} + $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} If ($State -eq 'Disabled'){ Write-Verbose "Disabling the NIC power management setting." @@ -113,8 +113,8 @@ function Test-TargetResource #Write-Debug "Use this cmdlet to write debug information while troubleshooting." - $nic = Get-WmiObject Win32_NetworkAdapter | where {$_.AdapterType -eq 'Ethernet 802.3'} - $powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} + $nic = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq 'Ethernet 802.3'} + $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} If ($State -eq 'Disabled'){ If ($powerMgmt.Enable -eq $false){ diff --git a/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 b/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 new file mode 100644 index 00000000..2750070e --- /dev/null +++ b/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 @@ -0,0 +1,97 @@ +$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 +} From ed01da34d4f0df04dafdfb75725a95417b7c63f3 Mon Sep 17 00:00:00 2001 From: sa-ericd Date: Fri, 28 Jul 2017 14:49:55 -0700 Subject: [PATCH 10/15] Fixed Test file --- tests/Unit/MSFT_xNetPowerManagement.tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 b/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 index 2750070e..939d95de 100644 --- a/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 +++ b/tests/Unit/MSFT_xNetPowerManagement.tests.ps1 @@ -88,6 +88,7 @@ try } } #end InModuleScope $DSCResourceName #endregion + } } finally { From dec70506d4f4ad17049d34b71b3d4d39f8653c0e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 22 May 2021 19:55:42 -0400 Subject: [PATCH 11/15] Fixed formatting --- .../MSFT_xNetPowerManagement.psm1 | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 index 9a9fb332..ccb933ef 100644 --- a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 +++ b/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 @@ -7,16 +7,15 @@ #> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [parameter(Mandatory = $true)] - [System.String] - $AdapterType - ) +function Get-TargetResource { + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $AdapterType + ) Write-Verbose "Getting the power setting on the network adpater." @@ -24,17 +23,18 @@ function Get-TargetResource $nic = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq 'Ethernet 802.3'} $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - If ($powerMgmt.Enable -eq $true){ + If ($powerMgmt.Enable -eq $true) { $State = $False - }ELSE{ + } + ELSE { $State = $true } $returnValue = @{ NICPowerSaving = $powerMgmt.Enable - AdapterType = $AdapterType - State = $State + AdapterType = $AdapterType + State = $State } $returnValue @@ -50,30 +50,29 @@ function Get-TargetResource .PARAMETER State Allows to set the state of the Network Adapter power management settings to disable to enable. #> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [parameter(Mandatory = $true)] - [System.String] - $AdapterType, +function Set-TargetResource { + [CmdletBinding()] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $AdapterType, - [ValidateSet("Enabled","Disabled")] - [System.String] - $State - ) + [ValidateSet("Enabled", "Disabled")] + [System.String] + $State + ) $nics = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq $AdapterType} - foreach ($nic in $nics) - { + foreach ($nic in $nics) { $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - If ($State -eq 'Disabled'){ + If ($State -eq 'Disabled') { Write-Verbose "Disabling the NIC power management setting." $powerMgmt.Enable = $False #Turn off PowerManagement feature - }ELSE{ + } + ELSE { Write-Verbose "Enabling the NIC power management setting." $powerMgmt.Enable = $true #Turn on PowerManagement feature } @@ -94,20 +93,19 @@ function Set-TargetResource .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] - $AdapterType, - - [ValidateSet("Enabled","Disabled")] - [System.String] - $State - ) +function Test-TargetResource { + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [parameter(Mandatory = $true)] + [System.String] + $AdapterType, + + [ValidateSet("Enabled", "Disabled")] + [System.String] + $State + ) Write-Verbose "Checking to see if the power setting on the NIC for Adapter Type $AdapterType." @@ -116,27 +114,29 @@ function Test-TargetResource $nic = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq 'Ethernet 802.3'} $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - If ($State -eq 'Disabled'){ - If ($powerMgmt.Enable -eq $false){ + If ($State -eq 'Disabled') { + If ($powerMgmt.Enable -eq $false) { Write-Verbose "NIC Power Management setting is disabled." $result = $true - }ELSE{ + } + ELSE { Write-Verbose "NIC Power Management setting is not disabled. - Disabling" $result = $false } } - If ($State -eq 'Enabled'){ + If ($State -eq 'Enabled') { If ($powerMgmt.Enable -eq $false) { Write-Verbose "NIC Power Management setting is disabled. - Enabling." $result = $false - }ELSE{ + } + ELSE { Write-Verbose "NIC Power Management setting is not disabled." $result = $true } } -$result + $result } From 12c4677f3951eb32fbbcd521a385ffe6fe00cc71 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 22 May 2021 20:01:00 -0400 Subject: [PATCH 12/15] Move to new directory structure --- .../MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 | 0 .../MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 => source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 (100%) rename Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.schema.mof => source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof (100%) diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 similarity index 100% rename from Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.psm1 rename to source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 diff --git a/Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.schema.mof b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof similarity index 100% rename from Modules/xNetworking/DSCResources/MSFT_xNetPowerManagement/MSFT_xNetPowerManagement.schema.mof rename to source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof From f1656b24b14c4c55b2c6c4465cc05e6805589c0c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 22 May 2021 20:42:35 -0400 Subject: [PATCH 13/15] begin modernization --- .../MSFT_NetPowerManagement.psm1 | 112 ++++++++++-------- .../MSFT_NetPowerManagement.schema.mof | 3 +- 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 index ccb933ef..d909dd2b 100644 --- a/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 +++ b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 @@ -1,32 +1,47 @@ -<# +$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 - Returns the current state of a Network Power Management. + Gets the power management features of the network adapter. .PARAMETER AdapterType - Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' - + Specifies the network adapter type you want to change. example 'Ethernet 802.3' #> - function Get-TargetResource { [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] + [OutputType([Hashtable])] param ( - [parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] + [System.String] + $AdapterType, + + [Parameter(Mandatory = $true)] + [ValidateSet('Enabled', 'Disabled')] [System.String] - $AdapterType + $State ) Write-Verbose "Getting the power setting on the network adpater." #Write-Debug "Use this cmdlet to write debug information while troubleshooting." - $nic = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq 'Ethernet 802.3'} + $nic = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq $AdapterType} $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - If ($powerMgmt.Enable -eq $true) { + if ($powerMgmt.Enable -eq $true) { $State = $False } - ELSE { + else { $State = $true } @@ -42,103 +57,98 @@ function Get-TargetResource { <# .SYNOPSIS - Sets the current state of a Network Power Management. + Sets the power management properties on the network adapter. .PARAMETER AdapterType - Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' + Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' .PARAMETER State - Allows to set the state of the Network Adapter power management settings to disable to enable. + Allows to set the state of the Network Adapter power management settings to disable to enable. #> function Set-TargetResource { [CmdletBinding()] param ( - [parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $AdapterType, - [ValidateSet("Enabled", "Disabled")] + [Parameter(Mandatory = $true)] + [ValidateSet('Enabled', 'Disabled')] [System.String] $State ) + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $script:localizedData.CheckingNetAdapterMessage + ) -join '') + + $currentState = Get-TargetResource @PSBoundParameters $nics = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq $AdapterType} foreach ($nic in $nics) { $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - - If ($State -eq 'Disabled') { + + if ($State -eq 'Disabled') { Write-Verbose "Disabling the NIC power management setting." $powerMgmt.Enable = $False #Turn off PowerManagement feature } - ELSE { + else { Write-Verbose "Enabling the NIC power management setting." $powerMgmt.Enable = $true #Turn on PowerManagement feature } - + $powerMgmt.psbase.Put() | Out-Null } - - } <# .SYNOPSIS - Test the current state of a Network Power Management. + Tests if the NetPowerManagement resource state is desired state. .PARAMETER AdapterType - Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' + Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' .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. + 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)] + [Parameter(Mandatory = $true)] [System.String] $AdapterType, - [ValidateSet("Enabled", "Disabled")] + [Parameter(Mandatory = $true)] + [ValidateSet('Enabled', 'Disabled')] [System.String] $State ) Write-Verbose "Checking to see if the power setting on the NIC for Adapter Type $AdapterType." - #Write-Debug "Use this cmdlet to write debug information while troubleshooting." + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($script:localizedData.NetPowerManagementMessage -f $AdapterType) + ) -join '') - $nic = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq 'Ethernet 802.3'} - $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} + $currentState = Get-TargetResource @PSBoundParameters - If ($State -eq 'Disabled') { - If ($powerMgmt.Enable -eq $false) { - Write-Verbose "NIC Power Management setting is disabled." - $result = $true - } - ELSE { - Write-Verbose "NIC Power Management setting is not disabled. - Disabling" - $result = $false - } - } + if ($currentState) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($script:localizedData.NetPowerManagementMessage -f $AdapterType, $currentState.State) + ) -join '') - If ($State -eq 'Enabled') { - If ($powerMgmt.Enable -eq $false) { - Write-Verbose "NIC Power Management setting is disabled. - Enabling." - $result = $false - } - ELSE { - Write-Verbose "NIC Power Management setting is not disabled." - $result = $true - } + return $currentState.State -eq $State } - $result + 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 index fd56e2b3..72cfd4c3 100644 --- a/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof +++ b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.schema.mof @@ -1,7 +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; + [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; }; From f0c55b9133c0e6b967f05810b3a784a21648e764 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 22 May 2021 21:04:07 -0400 Subject: [PATCH 14/15] NetPowerManagement: use NetAdapter module Instead of querying CIM classes, just use the cmdlets in the NetAdapter module --- .../MSFT_NetPowerManagement.psm1 | 87 ++++++++++--------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 index d909dd2b..c775e300 100644 --- a/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 +++ b/source/DSCResources/MSFT_NetPowerManagement/MSFT_NetPowerManagement.psm1 @@ -12,10 +12,10 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS - Gets the power management features of the network adapter. + Gets the power management state of the network adapter. - .PARAMETER AdapterType - Specifies the network adapter type you want to change. example 'Ethernet 802.3' + .PARAMETER Name + Specifies the name of the network adapter. #> function Get-TargetResource { [CmdletBinding()] @@ -24,7 +24,7 @@ function Get-TargetResource { ( [Parameter(Mandatory = $true)] [System.String] - $AdapterType, + $Name, [Parameter(Mandatory = $true)] [ValidateSet('Enabled', 'Disabled')] @@ -34,36 +34,35 @@ function Get-TargetResource { Write-Verbose "Getting the power setting on the network adpater." - #Write-Debug "Use this cmdlet to write debug information while troubleshooting." - $nic = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq $AdapterType} - $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} + $nic = Get-NetAdapterPowerManagement ` + -Name $Name ` + -IncludeHidden:$true - if ($powerMgmt.Enable -eq $true) { - $State = $False + if ($nic.DeviceSleepOnDisconnect -eq 'Inactive') { + $State = 'Disabled' } else { - $State = $true + $State = 'Enabled' } - - $returnValue = @{ - NICPowerSaving = $powerMgmt.Enable - AdapterType = $AdapterType - State = $State + return @{ + Name = $Name + State = $State } - - $returnValue } <# .SYNOPSIS Sets the power management properties on the network adapter. - .PARAMETER AdapterType - Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' + .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()] @@ -71,12 +70,16 @@ function Set-TargetResource { ( [Parameter(Mandatory = $true)] [System.String] - $AdapterType, + $Name, [Parameter(Mandatory = $true)] [ValidateSet('Enabled', 'Disabled')] [System.String] - $State + $State, + + [Parameter()] + [System.Boolean] + $NoRestart = $false ) Write-Verbose -Message ( @( @@ -84,31 +87,35 @@ function Set-TargetResource { $script:localizedData.CheckingNetAdapterMessage ) -join '') + $PSBoundParameters.Remove("NoRestart") $currentState = Get-TargetResource @PSBoundParameters - $nics = Get-CimClass Win32_NetworkAdapter | where-object {$_.AdapterType -eq $AdapterType} - foreach ($nic in $nics) { - $powerMgmt = Get-CimClass MSPower_DeviceEnable -Namespace root\wmi | where-object {$_.InstanceName.ToUpper().Contains($nic.PNPDeviceID)} - - if ($State -eq 'Disabled') { - Write-Verbose "Disabling the NIC power management setting." - $powerMgmt.Enable = $False #Turn off PowerManagement feature + if ($currentState.State -eq 'Disabled') + { + if ($State -eq 'Enabled') + { + Enable-NetAdapterPowerManagement ` + -Name $Name ` + -IncludeHidden:$true ` + -NoRestart:$NoRestart } - else { - Write-Verbose "Enabling the NIC power management setting." - $powerMgmt.Enable = $true #Turn on PowerManagement feature + } else { + if ($State -eq 'Disabled') + { + Disable-NetAdapterPowerManagement ` + -Name $Name ` + -IncludeHidden:$true ` + -NoRestart:$NoRestart } - - $powerMgmt.psbase.Put() | Out-Null } } <# .SYNOPSIS - Tests if the NetPowerManagement resource state is desired state. + Tests if the power management state of the network adapter is in the desired state. - .PARAMETER AdapterType - Specifies the name of the network adapter type you want to change. example 'Ethernet 802.3' + .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. @@ -120,7 +127,7 @@ function Test-TargetResource { ( [Parameter(Mandatory = $true)] [System.String] - $AdapterType, + $Name, [Parameter(Mandatory = $true)] [ValidateSet('Enabled', 'Disabled')] @@ -128,11 +135,11 @@ function Test-TargetResource { $State ) - Write-Verbose "Checking to see if the power setting on the NIC for Adapter Type $AdapterType." + Write-Verbose "Checking to see if the power setting on the NIC for $Name." Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($script:localizedData.NetPowerManagementMessage -f $AdapterType) + $($script:localizedData.NetPowerManagementMessage -f $Name) ) -join '') $currentState = Get-TargetResource @PSBoundParameters @@ -141,7 +148,7 @@ function Test-TargetResource { { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($script:localizedData.NetPowerManagementMessage -f $AdapterType, $currentState.State) + $($script:localizedData.NetPowerManagementMessage -f $Name, $currentState.State) ) -join '') return $currentState.State -eq $State From 0bfce25276537ddb8b8a0c279da0f9c60009db92 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 22 May 2021 21:10:42 -0400 Subject: [PATCH 15/15] Allow configuration of power saving settings on network adapters. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca6e7ead..2437a936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 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 ### Changed