diff --git a/resources/Microsoft.Windows.Setting.Language/Microsoft.Windows.Setting.Language.psd1 b/resources/Microsoft.Windows.Setting.Language/Microsoft.Windows.Setting.Language.psd1 deleted file mode 100644 index 2e758bbf..00000000 --- a/resources/Microsoft.Windows.Setting.Language/Microsoft.Windows.Setting.Language.psd1 +++ /dev/null @@ -1,135 +0,0 @@ -# -# Module manifest for module 'Microsoft.Windows.Setting.Language' -# -# Generated by: Microsoft Corporation -# -# Generated on: 04/11/2024 -# - -@{ - - # Script module or binary module file associated with this manifest. - RootModule = 'Microsoft.Windows.Setting.Language.psm1' - - # Version number of this module. - ModuleVersion = '0.1.0' - - # Supported PSEditions - # CompatiblePSEditions = @() - - # ID used to uniquely identify this module - GUID = '6ab8bbf6-ce28-4d33-a3ce-04c1cc16f139' - - # 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 Setting Language' - - # 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 = @("Language", "DisplayLanguage") - - # 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_Language', - 'PSDscResource_DisplayLanguage' - ) - - # 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.Language/Microsoft.Windows.Setting.Language.psm1 b/resources/Microsoft.Windows.Setting.Language/Microsoft.Windows.Setting.Language.psm1 deleted file mode 100644 index fc2ea0f6..00000000 --- a/resources/Microsoft.Windows.Setting.Language/Microsoft.Windows.Setting.Language.psm1 +++ /dev/null @@ -1,209 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -using namespace System.Collections.Generic - -$global:LocaleNameRegistryPath = 'HKCU:\Control Panel\International' -$global:LocaleUserProfilePath = 'HKCU:\Control Panel\International\User Profile' - -#region Functions -function Get-OsBuildVersion { - return [System.Environment]::OSVersion.Version.Build -} - -function TryGetRegistryValue { - param ( - [Parameter(Mandatory = $true)] - [string]$Key, - - [Parameter(Mandatory = $true)] - [string]$Property - ) - - if (Test-Path -Path $Key) { - try { - return (Get-ItemProperty -Path $Key | Select-Object -ExpandProperty $Property) - } catch { - Write-Verbose "Property `"$($Property)`" could not be found." - } - } else { - Write-Verbose 'Registry key does not exist.' - } -} - -function Get-LocaleList { - $localeList = Get-WinUserLanguageList - $out = [List[Language]]::new() - - foreach ($locale in $localeList) { - $language = [Language]::new($locale.LanguageTag, $true) - $out.Add($language) - } - - # section to include other languages that can be installed - # helpful for users to discover what packages can be installed - $allLangues = [System.Globalization.CultureInfo]::GetCultures('AllCultures') - foreach ($culture in $allLangues) { - if ($out.LocaleName -notcontains $culture.Name -and -not ([string]::IsNullOrEmpty($culture.Name))) { - $language = [Language]::new($culture.Name, $false) - $out.Add($language) - } - } - - return $out -} -#endregion Functions - -#region Classes -<# -.SYNOPSIS - The `Language` DSC Resource allows you to install, update, and uninstall languages on your local Windows machine. - -.PARAMETER LocaleName - The name of the language. This is the language tag that represents the language. For example, `en-US` represents English (United States). - To get a full list of languages available, use the `Get-LocaleList` function or Export() method. - -.PARAMETER Exist - Indicates whether the package should exist. Defaults to $true. - -.EXAMPLE - PS C:\> Invoke-DscResource -ModuleName Microsoft.Windows.Setting.Language -Name Language -Method Set -Property @{ LocaleName = 'en-US' } - - This example installs the English (United States) language on the local machine. -#> -[DscResource()] -class Language { - [DscProperty(Key)] - [string] $LocaleName - - [DscProperty()] - [bool] $Exist = $true - - static [hashtable] $InstalledLocality - - Language() { - [Language]::GetInstalledLocality() - } - - Language([string] $LocaleName, [bool] $Exist) { - $this.LocaleName = $LocaleName - $this.Exist = $Exist - } - - [Language] Get() { - $keyExist = [Language]::InstalledLocality.ContainsKey(($this.LocaleName)) - - $currentState = [Language]::InstalledLocality[$this.LocaleName] - - if (-not $keyExist) { - return [Language]::new($this.LocaleName, $false) - } - - return $currentState - } - - [void] Set() { - if ($this.Test()) { - return - } - - if ($this.Exist) { - # use the LanguagePackManagement module to install the language (requires elevation). International does not have a cmdlet to install language - Install-Language -Language $this.LocaleName - } else { - Uninstall-Language -Language $this.LocaleName - } - } - - [bool] Test() { - $currentState = $this.Get() - - if ($currentState.Exist -ne $this.Exist) { - return $false - } - - return $true - } - - static [Language[]] Export() { - return Get-LocaleList - } - - #region Language helper functions - static [void] GetInstalledLocality() { - [Language]::InstalledLocality = @{} - - foreach ($locality in [Language]::Export()) { - [Language]::InstalledLocality[$locality.LocaleName] = $locality - } - } - #endRegion Language helper functions -} - -<# -.SYNOPSIS - The `DisplayLanguage` DSC Resource allows you to set the display language on your local Windows machine. - -.PARAMETER LocaleName - The name of the display language. This is the language tag that represents the language. For example, `en-US` represents English (United States). - -.PARAMETER Exist - Indicates whether the display language should be set. Defaults to $true. - -.EXAMPLE - PS C:\> Invoke-DscResource -ModuleName Microsoft.Windows.Setting.Language -Name DisplayLanguage -Method Set -Property @{ LocaleName = 'en-US' } - - This example sets the display language to English (United States) on the user. -#> -[DscResource()] -class DisplayLanguage { - - [DscProperty(Key)] - [string] $LocaleName - - [DscProperty()] - [bool] $Exist = $true - - hidden [string] $KeyName = 'LocaleName' - - DisplayLanguage() { - } - - [DisplayLanguage] Get() { - $currentState = [DisplayLanguage]::new() - - # check if user profile contains display language - $userProfileLanguageDict = TryGetRegistryValue -Key (Join-Path $global:LocaleUserProfilePath $this.LocaleName) -Property 'CachedLanguageName' - if ((TryGetRegistryValue -Key $global:LocaleNameRegistryPath -Property $this.KeyName) -ne $this.LocaleName -and ($null -ne $userProfileLanguageDict)) { - $currentState.Exist = $false - return $currentState - } - - return @{ - LocaleName = $this.LocaleName - Exist = $true - } - } - - [void] Set() { - if ($this.Test()) { - return - } - - # TODO: How do we handle sign out and sign in? - Set-WinUserLanguageList -Language $this.LocaleName - - # TODO: Exist does not make sense here, we always want a language to exist - } - - [bool] Test() { - $currentState = $this.Get() - - if ($currentState.Exist -ne $this.Exist) { - return $false - } - - return $true - } -} -#endRegion classes diff --git a/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psd1 b/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psd1 deleted file mode 100644 index d044afd4..00000000 --- a/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psd1 +++ /dev/null @@ -1,134 +0,0 @@ -# -# 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 deleted file mode 100644 index 375ee96a..00000000 --- a/resources/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.psm1 +++ /dev/null @@ -1,295 +0,0 @@ -$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' - -#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)) { - $null = New-Item -Path $Path -Force - } - - 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 - } - - 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 - } - } - - $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)] - [nullable[int]] $UserChoiceActiveHoursEnd - - [DscProperty()] - [ValidateRange(0, 24)] - [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(5, 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] $RestartNotificationsAllowedProperty = '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 \ No newline at end of file diff --git a/resources/PythonPip3Dsc/PythonPip3Dsc.psd1 b/resources/PythonPip3Dsc/PythonPip3Dsc.psd1 index 72a38a2c..8dae9080 100644 --- a/resources/PythonPip3Dsc/PythonPip3Dsc.psd1 +++ b/resources/PythonPip3Dsc/PythonPip3Dsc.psd1 @@ -97,13 +97,13 @@ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - Tags = @('PSDscResource_Pip3Package') + Tags = @('PSDscResource_Pip3Package') # A URL to the license for this module. - LicenseUri = 'https://github.com/microsoft/winget-dsc/blob/main/LICENSE' + 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' + ProjectUri = 'https://github.com/microsoft/winget-dsc' # A URL to an icon representing this module. # IconUri = '' @@ -112,14 +112,13 @@ # ReleaseNotes = '' # Prerelease string of this module - Prerelease = 'alpha' + 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 = @() - DscCapabilities = @('Get', 'Set', 'Test', 'Export', 'WhatIf') } # End of PSData hashtable @@ -131,4 +130,6 @@ # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. # DefaultCommandPrefix = '' -} \ No newline at end of file +} + + diff --git a/resources/PythonPip3Dsc/PythonPip3Dsc.psm1 b/resources/PythonPip3Dsc/PythonPip3Dsc.psm1 index f9c22099..428fe494 100644 --- a/resources/PythonPip3Dsc/PythonPip3Dsc.psm1 +++ b/resources/PythonPip3Dsc/PythonPip3Dsc.psm1 @@ -4,61 +4,6 @@ using namespace System.Collections.Generic #region Functions -function Invoke-Process { - [CmdletBinding()] - param - ( - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] - [string]$FilePath, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [string]$ArgumentList - ) - - try { - $pinfo = New-Object System.Diagnostics.ProcessStartInfo - $pinfo.FileName = $FilePath - $pinfo.RedirectStandardError = $true - $pinfo.RedirectStandardOutput = $true - $pinfo.UseShellExecute = $false - $pinfo.WindowStyle = 'Hidden' - $pinfo.CreateNoWindow = $true - $pinfo.Arguments = $ArgumentList - $p = New-Object System.Diagnostics.Process - $p.StartInfo = $pinfo - $p.Start() | Out-Null - - $stOut = @() - # using ReadLine() instead of ReadToEnd() for building array object. ReadToEnd() gave different output than ReadLine() in some cases. - while (-not $p.StandardOutput.EndOfStream) { - $stOut += $p.StandardOutput.ReadLine() - } - - $stErr = @() - while (-not $p.StandardError.EndOfStream) { - $stErr += $p.StandardError.ReadLine() - } - - $result = [pscustomobject]@{ - Title = ($MyInvocation.MyCommand).Name - Command = $FilePath - Arguments = $ArgumentList - StdOut = $stOut - StdErr = $stErr - ExitCode = $p.ExitCode - } - - $p.WaitForExit() - - return $result - } catch { - Write-Verbose -Message "Error occurred while executing the command: $FilePath $ArgumentList. Error:" - Write-Verbose -Message $stErr - } -} - function Get-Pip3Path { if ($IsWindows) { # Note: When installing 64-bit version, the registry key: HKLM:\SOFTWARE\Wow6432Node\Python\PythonCore\*\InstallPath was empty. @@ -138,10 +83,7 @@ function Get-PackageNameWithVersion { [string]$Version, [Parameter()] - [switch]$IsUpdate, - - [Parameter()] - [switch]$DryRun + [switch]$IsUpdate ) if ($PSBoundParameters.ContainsKey('Version') -and -not ([string]::IsNullOrEmpty($Version))) { @@ -162,13 +104,8 @@ function Invoke-Pip3Install { [Parameter()] [string]$Version, - # not explicitly used, only to call from lower functions if parameters are passed - [Parameter()] - [switch]$IsUpdate, - - # not explicitly used, only to call from lower functions if parameters are passed [Parameter()] - [switch]$DryRun + [switch]$IsUpdate ) $command = [List[string]]::new() @@ -177,15 +114,8 @@ function Invoke-Pip3Install { if ($IsUpdate.IsPresent) { $command.Add('--force-reinstall') } - if ($DryRun.IsPresent) { - $command.Add('--dry-run') - } - $command.Add($Arguments) - Write-Verbose -Message "Executing 'pip' install with command: $command" - $result = Invoke-Pip3 -command $command - - return $result + return Invoke-Pip3 -command $command } function Invoke-Pip3Uninstall { @@ -205,7 +135,7 @@ function Invoke-Pip3Uninstall { $command.Add((Get-PackageNameWithVersion @PSBoundParameters)) $command.Add($Arguments) - # '--yes' is needed to ignore conformation required for uninstalls + # '--yes' is needed to ignore confirmation required for uninstalls $command.Add('--yes') return Invoke-Pip3 -command $command } @@ -281,9 +211,9 @@ function Invoke-Pip3 { ) if ($global:usePip3Exe) { - return Invoke-Process -FilePath $global:pip3ExePath -ArgumentList $command + return Start-Process -FilePath $global:pip3ExePath -ArgumentList $command -Wait -PassThru -WindowStyle Hidden } else { - return Invoke-Process -FilePath pip3 -ArgumentList $command + return Start-Process -FilePath pip3 -ArgumentList $command -Wait -PassThru -WindowStyle hidden } } @@ -409,29 +339,6 @@ class Pip3Package { } } - [string] WhatIf() { - if ($this.Exist) { - $whatIfState = Invoke-Pip3Install -PackageName $this.PackageName -Version $this.Version -Arguments $this.Arguments -DryRun - - $whatIfResult = $whatIfState.StdOut - if ($whatIfState.ExitCode -ne 0) { - $whatIfResult = $whatIfState.StdErr - } - - $out = @{ - PackageName = $this.PackageName - _metaData = @{ - whatIf = $whatIfResult - } - } - } else { - # Uninstall does not have --dry-run param - $out = @{} - } - - return ($out | ConvertTo-Json -Depth 10 -Compress) - } - static [Pip3Package[]] Export() { $packages = GetInstalledPip3Packages $out = [List[Pip3Package]]::new() @@ -464,4 +371,4 @@ class Pip3Package { #endRegion Pip3Package Helper functions } -#endregion DSCResources \ No newline at end of file +#endregion DSCResources diff --git a/tests/Microsoft.Windows.Setting.Language/Microsoft.Windows.Setting.Language.Tests.ps1 b/tests/Microsoft.Windows.Setting.Language/Microsoft.Windows.Setting.Language.Tests.ps1 deleted file mode 100644 index 8565fbfc..00000000 --- a/tests/Microsoft.Windows.Setting.Language/Microsoft.Windows.Setting.Language.Tests.ps1 +++ /dev/null @@ -1,70 +0,0 @@ -using module Microsoft.Windows.Setting.Language - -$ErrorActionPreference = "Stop" -Set-StrictMode -Version Latest - -<# -.Synopsis - Pester tests related to the Microsoft.Windows.Setting.Language PowerShell module. -#> - -BeforeAll { - Import-Module Microsoft.Windows.Setting.Language -Force -ErrorAction SilentlyContinue -} - -Describe 'List available DSC resources' { - It 'Shows DSC Resources' { - $expectedDSCResources = @("Language", "DisplayLanguage") - $availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Setting.Language).Name - $availableDSCResources.count | Should -Be 2 - $availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop - } -} - -Describe 'Language' { - It 'Install a preferred language' -Skip:(!$IsWindows) { - $desiredState = @{ - LocaleName = 'en-GB' - } - - Invoke-DscResource -Name Language -ModuleName Microsoft.Windows.Setting.Language -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name Language -ModuleName Microsoft.Windows.Setting.Language -Method Get -Property $desiredState - $finalState.Exist | Should -BeTrue - } - - It 'Uninstall a preferred language' -Skip:(!$IsWindows) { - $desiredState = @{ - LocaleName = 'en-GB' - } - - Invoke-DscResource -Name Pip3Package -ModuleName PythonPip3Dsc -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name Pip3Package -ModuleName PythonPip3Dsc -Method Get -Property $desiredState - $finalState.Exist | Should -BeFalse - } - - It 'Export all languages' -Skip:(!$IsWindows) { - - $class = [Language]::new() - - $currentLanguages = $class::Export() - $currentLanguages | Should -Not -BeNullOrEmpty - $currentLanguages.Count | Should -BeGreaterThan 0 - } - - # TODO: Add test if LocaleName is not found -} - -Describe 'DisplayLanguage' { - It 'Set a preferred language' -Skip:(!$IsWindows) { - $desiredState = @{ - LocaleName = 'en-US' - } - - Invoke-DscResource -Name DisplayLanguage -ModuleName Microsoft.Windows.Setting.Language -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name Language -ModuleName Microsoft.Windows.Setting.Language -Method Get -Property $desiredState - $finalState.Exist | Should -BeTrue - } -} \ No newline at end of file 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 deleted file mode 100644 index 229d2bce..00000000 --- a/tests/Microsoft.Windows.Setting.WindowsUpdate/Microsoft.Windows.Setting.WindowsUpdate.Tests.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -# 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 -} - -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 - } -} \ No newline at end of file diff --git a/utilities/scripts/New-DscResourceModule.ps1 b/utilities/scripts/New-DscResourceModule.ps1 deleted file mode 100644 index 24294f70..00000000 --- a/utilities/scripts/New-DscResourceModule.ps1 +++ /dev/null @@ -1,101 +0,0 @@ -function New-DscResourceModule -{ - <# - .SYNOPSIS - Creates a new DSC (Desired State Configuration) resource module structure. - - .DESCRIPTION - The function New-DscResourceModule function creates a new DSC resource module structure with the specified name and description. - It sets up the necessary directory structure for resources and tests within the given base path. - - .PARAMETER DscResourceModule - The name of the DSC resource module to create. - - .PARAMETER Description - A description of the DSC resource module. - - .PARAMETER BasePath - The base path where the DSC resource module structure will be created. The default value is the parent directory of the script. - - .EXAMPLE - PS C:\> New-DscResourceModule -DscResourceModule 'Microsoft.Windows.Language' -Description 'DSC Resource for Windows Language' - - This command creates a new DSC resource module named 'Microsoft.Windows.Language' with the specified description in the default base path. - #> - [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPositionalParameters", "", Justification = "Positional parameters are used for simplicity. Targeting PS 7+")] - param ( - [Parameter(Mandatory)] - [string]$DscResourceModule, - - [Parameter(Mandatory)] - [string]$Description, - - [Parameter()] - [string]$BasePath = (Join-Path $PSScriptRoot '..' '..') - - ) - - $resourcePath = Join-Path $BasePath 'resources' $DscResourceModule - $testsPath = Join-Path $BasePath 'tests' $DscResourceModule - - # Create directories if they do not exist - if (-not (Test-Path -Path $resourcePath)) - { - Write-Verbose -Message "Creating directory: $resourcePath" - $null = New-Item -ItemType Directory -Path $resourcePath -Force - } - - if (-not (Test-Path -Path $testsPath)) - { - Write-Verbose -Message "Creating test directory: $testsPath" - $null = New-Item -ItemType Directory -Path $testsPath -Force - } - - $moduleManifestPath = (Join-Path $BasePath 'resources' $DscResourceModule "$DscResourceModule.psd1") - - $moduleManifestParams = @{ - Path = $moduleManifestPath - RootModule = "$DscResourceModule.psm1" - ModuleVersion = '0.1.0' - Author = 'Microsoft Corporation' - CompanyName = 'Microsoft Corporation' - Copyright = '(c) Microsoft Corporation. All rights reserved.' - Description = $Description - PowerShellVersion = '7.2' - DscResourcesToExport = @() - } - - if (-not (Test-Path $moduleManifestPath)) - { - if ($PSCmdlet.ShouldProcess($moduleManifestPath, 'Create module manifest')) - { - Write-Verbose -Message ($moduleManifestParams | ConvertTo-Json -Depth 10 | Out-String) - New-ModuleManifest @moduleManifestParams - } - - # Workaround for issue: https://github.com/PowerShell/PowerShell/issues/5922 - $fileContent = Get-Content $moduleManifestPath - $newLicenseUri = "LicenseUri = 'https://github.com/microsoft/winget-dsc/blob/main/LICENSE'" - $fileContent = $fileContent -replace '# LicenseUri = ''''', $newLicenseUri - $newProjectUri = "ProjectUri = 'https://github.com/microsoft/winget-dsc'" - $fileContent = $fileContent -replace '# ProjectUri = ''''', $newProjectUri - $newPrerelease = "Prerelease = 'alpha'" - $fileContent = $fileContent -replace '# Prerelease = ''''', $newPrerelease - # TODO: Add tags - - Set-Content -Path $moduleManifestPath -Value $fileContent - } - - $psm1Path = Join-Path -Path $resourcePath -ChildPath "$DscResourceModule.psm1" - if (-not (Test-Path $psm1Path)) - { - $null = New-Item -ItemType File -Path $psm1Path -Force - } - - $testsFilePath = Join-Path -Path $testsPath -ChildPath "$DscResourceModule.Tests.ps1" - if (-not (Test-Path $testsFilePath)) - { - $null = New-Item -ItemType File -Path $testsFilePath -Force - } -} \ No newline at end of file