diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt index 1c720079..ec1b8a7c 100644 --- a/.github/actions/spelling/allow.txt +++ b/.github/actions/spelling/allow.txt @@ -1,3 +1,4 @@ + admins apps appwiz @@ -43,28 +44,6 @@ pscustomobject VGpu wildcards worktree -aspnetcore -bbwe -devdocs -echarts -ephemoral -Fancyzones -gdk -JDK -jquery -Mfor -msixbundle -NVM -powertoys -reduxjs -restsource -seperated -tastejs -todomvc -videojs -vsconfig +PCs +wmiprvse websites -wekyb -Hmmss -MMdd -MMdd \ No newline at end of file diff --git a/.github/actions/spelling/expect/generic_terms.txt b/.github/actions/spelling/expect/generic_terms.txt index 870c3e87..a2e61db5 100644 --- a/.github/actions/spelling/expect/generic_terms.txt +++ b/.github/actions/spelling/expect/generic_terms.txt @@ -19,4 +19,24 @@ ssh usr versioning VGpu +finalstate ADDLOCAL +aspnetcore +echarts +ephemoral +Fancyzones +gdk +Hmmss +JDK +jquery +Mfor +MMdd +NVM +reduxjs +restsource +seperated +tastejs +todomvc +videojs +vsconfig +websites \ No newline at end of file diff --git a/resources/Help/Microsoft.Windows.Setting.WindowsUpdate/WindowsUpdate.md b/resources/Help/Microsoft.Windows.Setting.WindowsUpdate/WindowsUpdate.md new file mode 100644 index 00000000..9fa02660 --- /dev/null +++ b/resources/Help/Microsoft.Windows.Setting.WindowsUpdate/WindowsUpdate.md @@ -0,0 +1,50 @@ +--- +external help file: Microsoft.Windows.Setting.Update.psm1-Help.xml +Module Name: Microsoft.Windows.Setting.Update +ms.date: 11/04/2024 +online version: +schema: 2.0.0 +title: WindowsUpdate +--- + +# WindowsUpdate + +## SYNOPSIS + +The `WindowsUpdate` DSC resource allows you to configure various Windows Update settings, including enabling or disabling specific update services, setting download and upload rates, and configuring active hours for updates. + +## DESCRIPTION + +The `WindowsUpdate` DSC resource allows you to configure various Windows Update settings, including enabling or disabling specific update services, setting download and upload rates, and configuring active hours for updates. + +## PARAMETERS + +| **Parameter** | **Attribute** | **DataType** | **Description** | **Allowed Values** | +| -------------------------------------------------- | ------------- | ------------ | -------------------------------------------------------------------------------- | ----------------------------------------------- | +| `SID` | Key | String | The security identifier. This is a key property and should not be set manually. | N/A | +| `IsContinuousInnovationOptedIn` | Optional | Boolean | Indicates whether the device is opted in to continuous innovation updates. | `$true`, `$false` | +| `AllowMUUpdateService` | Optional | Boolean | Allows updates from Microsoft Update service. | `$true`, `$false` | +| `IsExpedited` | Optional | Boolean | Indicates whether updates should be expedited. | `$true`, `$false` | +| `AllowAutoWindowsUpdateDownloadOverMeteredNetwork` | Optional | Boolean | Allows automatic Windows Update downloads over metered networks. | `$true`, `$false` | +| `RestartNotificationsAllowed` | Optional | Boolean | Allows restart notifications for updates. | `$true`, `$false` | +| `SmartActiveHoursState` | Optional | String | Configures smart active hours state for updates. | `Enabled`, `Disabled` | +| `UserChoiceActiveHoursEnd` | Optional | Integer | Specifies the end time for user-chosen active hours in `HH:MM` format. | Any valid time in `HH:MM` format | +| `UserChoiceActiveHoursStart` | Optional | Integer | Specifies the start time for user-chosen active hours in `HH:MM` format. | Any valid time in `HH:MM` format | +| `DownloadMode` | Optional | Integer | Specifies the download mode for updates. | `Foreground`, `Background`, `Bypass`, `None` | +| `DownloadRateBackgroundBps` | Optional | Integer | Specifies the background download rate for updates in Bps. | Any positive integer value. E.g. 20000 is 2MBPs | +| `DownloadRateForegroundBps` | Optional | Integer | Specifies the foreground download rate for updates in Bps. | Any positive integer value | +| `DownloadRateBackgroundPct` | Optional | Integer | Specifies the background download rate for updates as a percentage of bandwidth. | 0-100 | +| `DownloadRateForegroundPct` | Optional | Integer | Specifies the foreground download rate for updates as a percentage of bandwidth. | 0-100 | +| `UploadLimitGBMonth` | Optional | Integer | Specifies the upload limit for updates in GB per month. | 5-500 | +| `UpRatePctBandwidth` | Optional | Integer | Specifies the upload rate as a percentage of bandwidth. | 0-100 | + +## EXAMPLES + +### EXAMPLE 1 + +```powershell +$params = @{} +Invoke-DscResource -Name WindowsUpdate -Method Set -Property $params -ModuleName Microsoft.Windows.Setting.WindowsUpdate + +# This command gets the current Windows Update settings. +``` diff --git a/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psd1 b/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psd1 new file mode 100644 index 00000000..d044afd4 --- /dev/null +++ b/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psd1 @@ -0,0 +1,134 @@ +# +# Module manifest for module 'Microsoft.Windows.Setting.WindowsUpdate' +# +# Generated by: Microsoft Corporation +# +# Generated on: 04/11/2024 +# + +@{ + + # Script module or binary module file associated with this manifest. + RootModule = 'Microsoft.Windows.Setting.WindowsUpdate.psm1' + + # Version number of this module. + ModuleVersion = '0.1.0' + + # Supported PSEditions + # CompatiblePSEditions = @() + + # ID used to uniquely identify this module + GUID = '6a0a9e72-9797-4c28-94ca-ebfbef3d7116' + + # Author of this module + Author = 'Microsoft Corporation' + + # Company or vendor of this module + CompanyName = 'Microsoft Corporation' + + # Copyright statement for this module + Copyright = '(c) Microsoft Corporation. All rights reserved.' + + # Description of the functionality provided by this module + Description = 'DSC Resource for Windows Update Settings' + + # Minimum version of the PowerShell engine required by this module + PowerShellVersion = '7.2' + + # Name of the PowerShell host required by this module + # PowerShellHostName = '' + + # Minimum version of the PowerShell host required by this module + # PowerShellHostVersion = '' + + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' + + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # ClrVersion = '' + + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' + + # Modules that must be imported into the global environment prior to importing this module + # RequiredModules = @() + + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @() + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + # ScriptsToProcess = @() + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() + + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() + + # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + # FunctionsToExport = '*' + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + # CmdletsToExport = '*' + + # Variables to export from this module + # VariablesToExport = '*' + + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + # AliasesToExport = '*' + + # DSC resources to export from this module + DscResourcesToExport = @('WindowsUpdate') + + # List of all modules packaged with this module + # ModuleList = @() + + # List of all files packaged with this module + # FileList = @() + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @( + 'PSDscResource_WindowsUpdate' + ) + + # A URL to the license for this module. + LicenseUri = 'https://github.com/microsoft/winget-dsc/blob/main/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/microsoft/winget-dsc' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # Prerelease string of this module + Prerelease = 'alpha' + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false + + # External dependent modules of this module + # ExternalModuleDependencies = @() + + } # End of PSData hashtable + + } # End of PrivateData hashtable + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' + +} + diff --git a/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psm1 b/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psm1 new file mode 100644 index 00000000..35a16767 --- /dev/null +++ b/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psm1 @@ -0,0 +1,315 @@ +if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { + $global:WindowsUpdateSettingPath = 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings' + # The network service account using wmiprvse.exe sets values in the user hive. This is the path to the Delivery Optimization settings in the user hive. + # It requires elevation to read the values + # Other settings might be needed e.g. DownloadRateForegroundProvider, DownloadRateBackgroundProvider + $global:DeliveryOptimizationSettingPath = 'Registry::HKEY_USERS\S-1-5-20\Software\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings' +} else { + $global:WindowsUpdateSettingPath = $global:DeliveryOptimizationSettingPath = $env:TestRegistryPath +} + +#region Functions +function DoesRegistryKeyPropertyExist { + param ( + [Parameter(Mandatory)] + [string]$Path, + + [Parameter(Mandatory)] + [string]$Name + ) + + # Get-ItemProperty will return $null if the registry key property does not exist. + $itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue + return $null -ne $itemProperty +} + +function Test-WindowsUpdateRegistryKey { + param ( + [Parameter(Mandatory)] + [hashtable] $RegistryKeyProperty, + + [Parameter(Mandatory)] + [WindowsUpdate]$CurrentState + ) + + $result = $true + foreach ($key in $RegistryKeyProperty.Keys) { + $value = $RegistryKeyProperty[$key] + if ($value -ne $CurrentState.$key) { + $result = $false + } + } + + return $result +} + +function Set-WindowsUpdateRegistryKey { + param ( + [Parameter(Mandatory)] + [string]$Path, + + [Parameter()] + [AllowNull()] + [hashtable] $RegistryKeyProperty + ) + + if (-not (Test-Path -Path $Path)) { + New-Item -Path $Path -Force | Out-Null + } + + foreach ($key in $RegistryKeyProperty.Keys) { + $value = $RegistryKeyProperty[$key] + $typeInfo = $value.GetType().Name + + if ($typeInfo -eq 'Boolean') { + $value = [int]$value + } + + if (-not (DoesRegistryKeyPropertyExist -Path $Path -Name $key)) { + $null = New-ItemProperty -Path $Path -Name $key -Value $value -PropertyType 'DWord' -Force + } + + if ($key -eq 'UploadLimitGBMonth') { + if ($value -lt 5) { + Throw 'UploadLimitGBMonth must be greater than or equal to 5.' + } + } + + if ($key -eq 'RestartNotificationsAllowed') { + $key = 'RestartNotificationsAllowed2' + } + + Write-Verbose -Message "Setting $key to $($RegistryKeyProperty[$key])" + Set-ItemProperty -Path $Path -Name $key -Value $value + } +} + +function Assert-DownloadRate { + param ( + [Parameter(Mandatory)] + [hashtable] $Parameters + ) + + if ($Parameters.ContainsKey('DownloadRateBackgroundPct') -or $Parameters.ContainsKey('DownloadRateForegroundPct')) { + if ($Parameters.ContainsKey('DownloadRateBackgroundBps') -or $Parameters.ContainsKey('DownloadRateForegroundBps')) { + Throw 'Cannot set both DownloadRateBackgroundPct/DownloadRateForegroundPct and DownloadRateBackgroundBps/DownloadRateForegroundBps' + } + } +} + +function Initialize-WindowsUpdate { + $class = [WindowsUpdate]::new() + + $hiddenProperties = $class | Get-Member -Static -Force | Where-Object { $_.MemberType -eq 'Property' } | Select-Object -ExpandProperty Name + + foreach ($p in $hiddenProperties) { + $classPropertyName = $p.Replace('Property', '') + $dataType = $class | Get-Member | Where-Object { $_.Name -eq $classPropertyName } | Select-Object -ExpandProperty Definition | Select-String -Pattern '\[.*\]' | Select-Object -ExpandProperty Matches | Select-Object -ExpandProperty Value + + $currentValue = [WindowsUpdate]::GetRegistryValue($class::$p) + if ($null -eq $currentValue) { + if ($dataType -eq '[bool]') { + $currentValue = $false + } + + if ($dataType -eq '[int]') { + $currentValue = 0 + } + } + + if ($classPropertyName -eq 'RestartNotificationsAllowed2') { + $classPropertyName = 'RestartNotificationsAllowed' + } + + $class.$classPropertyName = $currentValue + } + + return $class +} +#endregion Functions + +#region Classes +<# +.SYNOPSIS + The `WindowsUpdate` DSC resource allows you to configure various Windows Update settings, including enabling or disabling specific update services, setting download and upload rates, and configuring active hours for updates. + +.PARAMETER SID + The security identifier. This is a key property and should not be set manually. + +.PARAMETER IsContinuousInnovationOptedIn + Indicates whether the device is opted in for continuous innovation updates. This is the setting in Windows Update settings -> Get the latest updates as soon as they're available. + +.PARAMETER AllowMUUpdateService + Indicates whether the Microsoft Update service is allowed. This is the setting in Windows Update settings -> Advanced options -> Receive updates for other Microsoft products. + +.PARAMETER IsExpedited + Indicates whether the updates are expedited. This is the setting in Windows Update settings -> Advanced options -> Get me up to date. + +.PARAMETER AllowAutoWindowsUpdateDownloadOverMeteredNetwork + Indicates whether automatic Windows Update downloads are allowed over metered networks. This is the setting in Windows Update settings -> Advanced options -> Download updates over metered connections. + +.PARAMETER RestartNotificationsAllowed + Indicates whether restart notifications are allowed. This is the setting in Windows Update settings -> Advanced options -> Notify me when a restart is required to finish updating. + +.PARAMETER SmartActiveHoursState + Indicates whether smart active hours are enabled. + +.PARAMETER UserChoiceActiveHoursEnd + The end time for user-chosen active hours. + +.PARAMETER UserChoiceActiveHoursStart + The start time for user-chosen active hours. + +.PARAMETER DownloadMode + The download mode for updates. Valid values are 0, 1, and 3. This is the setting in Windows Update settings -> Advanced options -> Delivery Optimization -> Allow downloads from other PCs. + +.PARAMETER DownloadRateBackgroundBps + The background download rate in bits per second. + +.PARAMETER DownloadRateForegroundBps + The foreground download rate in bits per second. + +.PARAMETER DownloadRateBackgroundPct + The background download rate as a percentage. + +.PARAMETER DownloadRateForegroundPct + The foreground download rate as a percentage. + +.PARAMETER UploadLimitGBMonth + The upload limit in gigabytes per month. + +.PARAMETER UpRatePctBandwidth + The upload rate as a percentage of bandwidth. + +.EXAMPLE + PS C:\> Invoke-DscResource -Name WindowsUpdate -Method Get -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Property @{} + + This command gets the current Windows Update settings. +#> +[DSCResource()] +class WindowsUpdate { + # Key required. Do not set. + [DscProperty(Key)] + [string] $SID + + [DscProperty()] + [nullable[bool]] $IsContinuousInnovationOptedIn + + [DscProperty()] + [nullable[bool]] $AllowMUUpdateService + + [DscProperty()] + [nullable[bool]] $IsExpedited + + [DscProperty()] + [nullable[bool]] $AllowAutoWindowsUpdateDownloadOverMeteredNetwork + + [DscProperty()] + [nullable[bool]] $RestartNotificationsAllowed + + [DscProperty()] + [nullable[bool]] $SmartActiveHoursState + + [DscProperty()] + [ValidateRange(0, 24)] + [AllowNull()] + [nullable[int]] $UserChoiceActiveHoursEnd + + [DscProperty()] + [ValidateRange(0, 24)] + [AllowNull()] + [nullable[int]] $UserChoiceActiveHoursStart + + [DscProperty()] + [ValidateSet(0, 1, 3)] + [nullable[int]] $DownloadMode + + [DscProperty()] + [nullable[int]] $DownloadRateBackgroundBps + + [DscProperty()] + [nullable[int]] $DownloadRateForegroundBps + + [DscProperty()] + [ValidateRange(0, 100)] + [nullable[int]] $DownloadRateBackgroundPct + + [DscProperty()] + [ValidateRange(0, 100)] + [nullable[int]] $DownloadRateForegroundPct + + [DscProperty()] + [ValidateRange(0, 500)] + [nullable[int]] $UploadLimitGBMonth + + [DscProperty()] + [ValidateRange(0, 100)] + [nullable[int]] $UpRatePctBandwidth + + static hidden [string] $IsContinuousInnovationOptedInProperty = 'IsContinuousInnovationOptedIn' + static hidden [string] $AllowMUUpdateServiceProperty = 'AllowMUUpdateService' + static hidden [string] $IsExpeditedProperty = 'IsExpedited' + static hidden [string] $AllowAutoWindowsUpdateDownloadOverMeteredNetworkProperty = 'AllowAutoWindowsUpdateDownloadOverMeteredNetwork' + static hidden [string] $RestartNotificationsAllowed2Property = 'RestartNotificationsAllowed2' + static hidden [string] $SmartActiveHoursStateProperty = 'SmartActiveHoursState' + static hidden [string] $UserChoiceActiveHoursEndProperty = 'UserChoiceActiveHoursEnd' + static hidden [string] $UserChoiceActiveHoursStartProperty = 'UserChoiceActiveHoursStart' + static hidden [string] $DownloadModeProperty = 'DownloadMode' + static hidden [string] $DownloadRateBackgroundBpsProperty = 'DownloadRateBackgroundBps' + static hidden [string] $DownloadRateForegroundBpsProperty = 'DownloadRateForegroundBps' + static hidden [string] $DownloadRateBackgroundPctProperty = 'DownloadRateBackgroundPct' + static hidden [string] $DownloadRateForegroundPctProperty = 'DownloadRateForegroundPct' + static hidden [string] $UploadLimitGBMonthProperty = 'UploadLimitGBMonth' + static hidden [string] $UpRatePctBandwidthProperty = 'UpRatePctBandwidth' + + [WindowsUpdate] Get() { + $currentState = Initialize-WindowsUpdate + + return $currentState + } + + [bool] Test() { + $currentState = $this.Get() + $settableProperties = $this.GetParameters() + return (Test-WindowsUpdateRegistryKey -RegistryKeyProperty $settableProperties -CurrentState $currentState) + } + + [void] Set() { + if ($this.Test()) { + return + } + + $parameters = $this.GetParameters() + + Assert-DownloadRate -Parameters $parameters + + Set-WindowsUpdateRegistryKey -Path $global:WindowsUpdateSettingPath -RegistryKeyProperty $parameters + } + + #region WindowsUpdate helper functions + static [object] GetRegistryValue($PropertyName) { + $value = $null + if ($null -ne $PropertyName) { + if ((DoesRegistryKeyPropertyExist -Path $global:WindowsUpdateSettingPath -Name $PropertyName)) { + $value = Get-ItemProperty -Path $global:WindowsUpdateSettingPath -Name $PropertyName | Select-Object -ExpandProperty $PropertyName + } elseif ((DoesRegistryKeyPropertyExist -Path $global:DeliveryOptimizationSettingPath -Name $PropertyName)) { + $value = Get-ItemProperty -Path $global:DeliveryOptimizationSettingPath -Name $PropertyName | Select-Object -ExpandProperty $PropertyName + } + } + + return $value + } + + [hashtable] GetParameters() { + $parameters = @{} + foreach ($property in $this.PSObject.Properties) { + if (-not ([string]::IsNullOrEmpty($property.Value))) { + $parameters[$property.Name] = $property.Value + } + } + + return $parameters + } + #endRegion WindowsUpdate helper functions +} +#endRegion classes diff --git a/tests/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.Tests.ps1 b/tests/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.Tests.ps1 new file mode 100644 index 00000000..1395bfe0 --- /dev/null +++ b/tests/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.Tests.ps1 @@ -0,0 +1,116 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +using module Microsoft.Windows.Setting.WindowsUpdate + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest + +<# +.Synopsis + Pester tests related to the Microsoft.Windows.Setting.WindowsUpdate PowerShell module. +#> + +BeforeAll { + Import-Module Microsoft.Windows.Setting.WindowsUpdate + + $currentState = Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Get -Property @{} + + $global:Parameters = $currentState.GetParameters() + + Write-Verbose ("Current state: `n{0}" -f $($global:Parameters | ConvertTo-Json | Out-String)) -Verbose +} + +Describe 'List available DSC resources' { + It 'Shows DSC Resources' { + $expectedDSCResources = 'WindowsUpdate' + $availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Setting.WindowsUpdate).Name + $availableDSCResources.count | Should -Be 1 + $availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop + } +} + +Describe 'WindowsUpdate' { + It 'Keeps current value.' { + $initialState = Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Get -Property @{} + + $parameters = $initialState.GetParameters() + + $testResult = Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Get -Property @{} + $finalState.IsContinuousInnovationOptedIn | Should -Be $initialState.IsContinuousInnovationOptedIn + $finalState.AllowMUUpdateService | Should -Be $initialState.AllowMUUpdateService + $finalState.IsExpedited | Should -Be $initialState.IsExpedited + $finalState.AllowAutoWindowsUpdateDownloadOverMeteredNetwork | Should -Be $initialState.AllowAutoWindowsUpdateDownloadOverMeteredNetwork + $finalState.RestartNotificationsAllowed | Should -Be $initialState.RestartNotificationsAllowed + $finalState.SmartActiveHoursState | Should -Be $initialState.SmartActiveHoursState + $finalstate.UserChoiceActiveHoursEnd | Should -Be $initialState.UserChoiceActiveHoursEnd + $finalstate.UserChoiceActiveHoursStart | Should -Be $initialState.UserChoiceActiveHoursStart + $finalState.DownloadMode | Should -Be $initialState.DownloadMode + $finalState.DownloadRateBackgroundBps | Should -Be $initialState.DownloadRateBackgroundBps + $finalState.DownloadRateForegroundBps | Should -Be $initialState.DownloadRateForegroundBps + $finalstate.DownloadRateBackgroundPct | Should -Be $initialState.DownloadRateBackgroundPct + $finalstate.DownloadRateForegroundPct | Should -Be $initialState.DownloadRateForegroundPct + $finalState.UploadLimitGBMonth | Should -Be $initialState.UploadLimitGBMonth + $finalState.UpRatePctBandwidth | Should -Be $initialState.UpRatePctBandwidth + + } + + It 'Sets desired value with only background' { + $desiredState = @{ + IsContinuousInnovationOptedIn = $true + AllowMUUpdateService = $true + IsExpedited = $true + AllowAutoWindowsUpdateDownloadOverMeteredNetwork = $true + RestartNotificationsAllowed = $true + SmartActiveHoursState = 1 + UserChoiceActiveHoursEnd = 10 + UserChoiceActiveHoursStart = 2 + DownloadMode = 1 + DownloadRateBackgroundBps = 100 + DownloadRateForegroundBps = 100 + UploadLimitGBMonth = 100 + UpRatePctBandwidth = 100 + } + + Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Get -Property @{} + $finalState.IsContinuousInnovationOptedIn | Should -Be $desiredState.IsContinuousInnovationOptedIn + $finalState.AllowMUUpdateService | Should -Be $desiredState.AllowMUUpdateService + $finalState.IsExpedited | Should -Be $desiredState.IsExpedited + $finalState.AllowAutoWindowsUpdateDownloadOverMeteredNetwork | Should -Be $desiredState.AllowAutoWindowsUpdateDownloadOverMeteredNetwork + $finalState.RestartNotificationsAllowed | Should -Be $desiredState.RestartNotificationsAllowed + $finalState.SmartActiveHoursState | Should -Be $desiredState.SmartActiveHoursState + $finalstate.UserChoiceActiveHoursEnd | Should -Be $desiredState.UserChoiceActiveHoursEnd + $finalstate.UserChoiceActiveHoursStart | Should -Be $desiredState.UserChoiceActiveHoursStart + $finalState.DownloadMode | Should -Be $desiredState.DownloadMode + $finalState.DownloadRateBackgroundBps | Should -Be $desiredState.DownloadRateBackgroundBps + $finalState.DownloadRateForegroundBps | Should -Be $desiredState.DownloadRateForegroundBps + $finalState.UploadLimitGBMonth | Should -Be $desiredState.UploadLimitGBMonth + $finalState.UpRatePctBandwidth | Should -Be $desiredState.UpRatePctBandwidth + } + + It 'Sets desired value with only background rate' { + $desiredState = @{ + DownloadRateBackgroundPct = 50 + DownloadRateForegroundPct = 100 + } + + Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Get -Property @{} + $finalState.DownloadRateBackgroundPct | Should -Be $desiredState.DownloadRateBackgroundPct + $finalState.DownloadRateForegroundPct | Should -Be $desiredState.DownloadRateForegroundPct + } +} + +AfterAll { + Write-Verbose -Message 'Restoring the machine to the original state.' -Verbose + $global:Parameters.Remove('DownloadRateBackgroundPct') + $global:Parameters.Remove('DownloadRateForegroundPct') + Invoke-DscResource -Name WindowsUpdate -ModuleName Microsoft.Windows.Setting.WindowsUpdate -Method Set -Property $global:Parameters +} diff --git a/tests/PythonPip3Dsc/PythonPip3Dsc.Tests.ps1 b/tests/PythonPip3Dsc/PythonPip3Dsc.Tests.ps1 index 25389c12..607bd8a6 100644 --- a/tests/PythonPip3Dsc/PythonPip3Dsc.Tests.ps1 +++ b/tests/PythonPip3Dsc/PythonPip3Dsc.Tests.ps1 @@ -120,7 +120,6 @@ Describe 'Pip3Package' { # Call whatif to see if it "will" install $whatIf = $pipPackage.WhatIf() | ConvertFrom-Json - $whatIf.PackageName | Should -Be 'itsdangerous' $whatIf._metaData.whatIf | Should -Contain "Would install itsdangerous-$($whatIfState.Version)" } @@ -132,7 +131,6 @@ Describe 'Pip3Package' { $pipPackage = [Pip3Package]$whatIfState $whatIf = $pipPackage.WhatIf() | ConvertFrom-Json - $whatIf.PackageName | Should -Be 'invalidPackageName' $whatIf._metaData.whatIf | Should -Contain "ERROR: No matching distribution found for $($whatIfState.PackageName)"