From c0c7ddef9c07a4246eec83b367b8146c859b40a7 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 22 Aug 2023 19:06:56 +0200 Subject: [PATCH] SqlServerDsc: Update pipeline files from Sampler --- CHANGELOG.md | 1 + RequiredModules.psd1 | 20 +- Resolve-Dependency.ps1 | 614 ++++++++++++------ build.ps1 | 29 +- .../SqlRS/4-CompleteWithTwoInstances.ps1 | 4 +- .../SqlScript/3-RunScriptCompleteExample.ps1 | 6 +- .../3-RunScriptCompleteExample.ps1 | 1 - .../DSC_SqlAlwaysOnService.config.ps1 | 12 +- tests/Integration/DSC_SqlLogin.config.ps1 | 10 +- tests/Integration/DSC_SqlRS.config.ps1 | 16 +- tests/Integration/DSC_SqlRSSetup.config.ps1 | 4 +- .../Integration/DSC_SqlRS_Default.config.ps1 | 16 +- .../Integration/DSC_SqlReplication.config.ps1 | 12 +- tests/Integration/DSC_SqlScript.config.ps1 | 8 +- .../DSC_SqlServiceAccount.config.ps1 | 12 +- tests/Integration/DSC_SqlSetup.config.ps1 | 54 +- .../DSC_SqlWindowsFirewall.config.ps1 | 2 +- 17 files changed, 515 insertions(+), 306 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c619041627..da508b7bc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix a path in VS Code workspace settings to correctly use Script Analyzer on Linux and macOS. - Highlighted note comments throughout markdown and generated markdown. + - Updated pipeline files to support ModuleFast. - SqlServerDsc.Common - Fix unit tests so they work cross-platform. - ScriptAnalyzer.Tests was fixed so they work cross-platform. diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index d01c26cb0c..a996336ed5 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -15,12 +15,14 @@ If preview release of Pester prevents release we should temporary shift back to stable. #> - Pester = @{ - Version = 'latest' - Parameters = @{ - AllowPrerelease = $true - } - } + # Pester = @{ + # Version = 'latest' + # Parameters = @{ + # AllowPrerelease = $true + # } + # } + + Pester = 'latest' Plaster = 'latest' ModuleBuilder = 'latest' @@ -47,8 +49,8 @@ PSPKI = '3.7.2' # Prerequisites modules needed for examples or integration tests - PSDscResources = '2.12.0.0' - StorageDsc = '4.9.0.0' - NetworkingDsc = '7.4.0.0' + xPSDesiredStateConfiguration = '9.1.0' + StorageDsc = '5.1.0' + NetworkingDsc = '9.0.0' WSManDsc = '3.1.1' } diff --git a/Resolve-Dependency.ps1 b/Resolve-Dependency.ps1 index f05a1ab124..a4e71aefa1 100644 --- a/Resolve-Dependency.ps1 +++ b/Resolve-Dependency.ps1 @@ -9,7 +9,7 @@ .PARAMETER PSDependTarget Path for PSDepend to be bootstrapped and save other dependencies. Can also be CurrentUser or AllUsers if you wish to install the modules in - such scope. The default value is './output/RequiredModules' relative to + such scope. The default value is 'output/RequiredModules' relative to this script's path. .PARAMETER Proxy @@ -46,6 +46,10 @@ .PARAMETER WithYAML Not yet written. + .PARAMETER UseModuleFast + Specifies to use ModuleFast instead of PowerShellGet to resolve dependencies + faster. + .NOTES Load defaults for parameters values from Resolve-Dependency.psd1 if not provided as parameter. @@ -59,7 +63,7 @@ param [Parameter()] [System.String] - $PSDependTarget = (Join-Path -Path $PSScriptRoot -ChildPath './output/RequiredModules'), + $PSDependTarget = (Join-Path -Path $PSScriptRoot -ChildPath 'output/RequiredModules'), [Parameter()] [System.Uri] @@ -96,9 +100,33 @@ param [Parameter()] [System.Management.Automation.SwitchParameter] - $WithYAML + $WithYAML, + + [Parameter()] + [System.Collections.Hashtable] + $RegisterGallery, + + [Parameter()] + [System.Management.Automation.SwitchParameter] + $UseModuleFast ) +try +{ + if ($UseModuleFast.IsPresent) + { + # Uses instructions from https://github.com/JustinGrote/ModuleFast. + Invoke-WebRequest -Uri 'bit.ly/modulefast' | + Invoke-Expression + } +} +catch +{ + Write-Warning -Message 'ModuleFast could not be bootstrapped. Reverting to PowerShellGet'. + + $UseModuleFast = $false +} + try { if ($PSVersionTable.PSVersion.Major -le 5) @@ -108,16 +136,19 @@ try Import-Module -Name Microsoft.PowerShell.Utility -RequiredVersion '3.1.0.0' } - <# - Making sure the imported PackageManagement module is not from PS7 module - path. The VSCode PS extension is changing the $env:PSModulePath and - prioritize the PS7 path. This is an issue with PowerShellGet because - it loads an old version if available (or fail to load latest). - #> - Get-Module -ListAvailable PackageManagement | - Where-Object -Property 'ModuleBase' -NotMatch 'powershell.7' | - Select-Object -First 1 | - Import-Module -Force + if (-not $UseModuleFast.IsPresent) + { + <# + Making sure the imported PackageManagement module is not from PS7 module + path. The VSCode PS extension is changing the $env:PSModulePath and + prioritize the PS7 path. This is an issue with PowerShellGet because + it loads an old version if available (or fail to load latest). + #> + Get-Module -ListAvailable PackageManagement | + Where-Object -Property 'ModuleBase' -NotMatch 'powershell.7' | + Select-Object -First 1 | + Import-Module -Force + } } Write-Verbose -Message 'Importing Bootstrap default parameters from ''$PSScriptRoot/Resolve-Dependency.psd1''.' @@ -138,7 +169,7 @@ try { if (-not $PSBoundParameters.Keys.Contains($parameterName) -and $resolveDependencyDefaults.ContainsKey($parameterName)) { - Write-Verbose -Message "Setting $parameterName with $($resolveDependencyDefaults[$parameterName])." + Write-Verbose -Message "Setting parameter '$parameterName' to value '$($resolveDependencyDefaults[$parameterName])'." try { @@ -151,7 +182,7 @@ try $PSBoundParameters.Add($parameterName, $variableValue) - Set-Variable -Name $parameterName -value $variableValue -Force -ErrorAction 'SilentlyContinue' + Set-Variable -Name $parameterName -Value $variableValue -Force -ErrorAction 'SilentlyContinue' } catch { @@ -165,303 +196,464 @@ catch Write-Warning -Message "Error attempting to import Bootstrap's default parameters from '$resolveDependencyConfigPath': $($_.Exception.Message)." } -Write-Progress -Activity 'Bootstrap:' -PercentComplete 0 -CurrentOperation 'NuGet Bootstrap' - -$importModuleParameters = @{ - Name = 'PowerShellGet' - MinimumVersion = '2.0' - ErrorAction = 'SilentlyContinue' - PassThru = $true -} - -if ($AllowOldPowerShellGetModule) +if (-not $UseModuleFast.IsPresent) { - $importModuleParameters.Remove('MinimumVersion') -} - -$powerShellGetModule = Import-Module @importModuleParameters + Write-Progress -Activity 'Bootstrap:' -PercentComplete 0 -CurrentOperation 'NuGet Bootstrap' -# Install the package provider if it is not available. -$nuGetProvider = Get-PackageProvider -Name 'NuGet' -ListAvailable -ErrorAction 'SilentlyContinue' | - Select-Object -First 1 + $importModuleParameters = @{ + Name = 'PowerShellGet' + MinimumVersion = '2.0' + ErrorAction = 'SilentlyContinue' + PassThru = $true + } -if (-not $powerShellGetModule -and -not $nuGetProvider) -{ - $providerBootstrapParameters = @{ - Name = 'NuGet' - Force = $true - ForceBootstrap = $true - ErrorAction = 'Stop' - Scope = 'CurrentUser' + if ($AllowOldPowerShellGetModule) + { + $importModuleParameters.Remove('MinimumVersion') } - switch ($PSBoundParameters.Keys) + $powerShellGetModule = Import-Module @importModuleParameters + + # Install the package provider if it is not available. + $nuGetProvider = Get-PackageProvider -Name 'NuGet' -ListAvailable -ErrorAction 'SilentlyContinue' | + Select-Object -First 1 + + if (-not $powerShellGetModule -and -not $nuGetProvider) { - 'Proxy' - { - $providerBootstrapParameters.Add('Proxy', $Proxy) + $providerBootstrapParameters = @{ + Name = 'NuGet' + Force = $true + ForceBootstrap = $true + ErrorAction = 'Stop' + Scope = $Scope } - 'ProxyCredential' + switch ($PSBoundParameters.Keys) { - $providerBootstrapParameters.Add('ProxyCredential', $ProxyCredential) - } + 'Proxy' + { + $providerBootstrapParameters.Add('Proxy', $Proxy) + } - 'Scope' - { - $providerBootstrapParameters.Scope = $Scope + 'ProxyCredential' + { + $providerBootstrapParameters.Add('ProxyCredential', $ProxyCredential) + } + + 'AllowPrerelease' + { + $providerBootstrapParameters.Add('AllowPrerelease', $AllowPrerelease) + } } + + Write-Information -MessageData 'Bootstrap: Installing NuGet Package Provider from the web (Make sure Microsoft addresses/ranges are allowed).' + + $null = Install-PackageProvider @providerBootstrapParameters + + $nuGetProvider = Get-PackageProvider -Name 'NuGet' -ListAvailable | Select-Object -First 1 + + $nuGetProviderVersion = $nuGetProvider.Version.ToString() + + Write-Information -MessageData "Bootstrap: Importing NuGet Package Provider version $nuGetProviderVersion to current session." + + $Null = Import-PackageProvider -Name 'NuGet' -RequiredVersion $nuGetProviderVersion -Force } - if ($AllowPrerelease) + if ($RegisterGallery) { - $providerBootstrapParameters.Add('AllowPrerelease', $true) - } + if ($RegisterGallery.ContainsKey('Name') -and -not [System.String]::IsNullOrEmpty($RegisterGallery.Name)) + { + $Gallery = $RegisterGallery.Name + } + else + { + $RegisterGallery.Name = $Gallery + } - Write-Information -MessageData 'Bootstrap: Installing NuGet Package Provider from the web (Make sure Microsoft addresses/ranges are allowed).' -InformationAction 'Continue' + Write-Progress -Activity 'Bootstrap:' -PercentComplete 7 -CurrentOperation "Verifying private package repository '$Gallery'" -Completed - $null = Install-PackageProvider @providerBootstrapParameters + $previousRegisteredRepository = Get-PSRepository -Name $Gallery -ErrorAction 'SilentlyContinue' - $nuGetProvider = Get-PackageProvider -Name 'NuGet' -ListAvailable | Select-Object -First 1 + if ($previousRegisteredRepository.SourceLocation -ne $RegisterGallery.SourceLocation) + { + if ($previousRegisteredRepository) + { + Write-Progress -Activity 'Bootstrap:' -PercentComplete 9 -CurrentOperation "Re-registrering private package repository '$Gallery'" -Completed - $nuGetProviderVersion = $nuGetProvider.Version.ToString() + Unregister-PSRepository -Name $Gallery - Write-Information -MessageData "Bootstrap: Importing NuGet Package Provider version $nuGetProviderVersion to current session." -InformationAction 'Continue' + $unregisteredPreviousRepository = $true + } + else + { + Write-Progress -Activity 'Bootstrap:' -PercentComplete 9 -CurrentOperation "Registering private package repository '$Gallery'" -Completed + } - $Null = Import-PackageProvider -Name 'NuGet' -RequiredVersion $nuGetProviderVersion -Force -} + Register-PSRepository @RegisterGallery + } + } -Write-Progress -Activity 'Bootstrap:' -PercentComplete 10 -CurrentOperation "Ensuring Gallery $Gallery is trusted" + Write-Progress -Activity 'Bootstrap:' -PercentComplete 10 -CurrentOperation "Ensuring Gallery $Gallery is trusted" -# Fail if the given PSGallery is not registered. -$previousGalleryInstallationPolicy = (Get-PSRepository -Name $Gallery -ErrorAction 'Stop').InstallationPolicy + # Fail if the given PSGallery is not registered. + $previousGalleryInstallationPolicy = (Get-PSRepository -Name $Gallery -ErrorAction 'Stop').InstallationPolicy -Set-PSRepository -Name $Gallery -InstallationPolicy 'Trusted' -ErrorAction 'Ignore' + if ($previousGalleryInstallationPolicy -ne 'Trusted') + { + # Only change policy if the repository is not trusted + Set-PSRepository -Name $Gallery -InstallationPolicy 'Trusted' -ErrorAction 'Ignore' + } +} try { - Write-Progress -Activity 'Bootstrap:' -PercentComplete 25 -CurrentOperation 'Checking PowerShellGet' + if (-not $UseModuleFast.IsPresent) + { + Write-Progress -Activity 'Bootstrap:' -PercentComplete 25 -CurrentOperation 'Checking PowerShellGet' - # Ensure the module is loaded and retrieve the version you have. - $powerShellGetVersion = (Import-Module -Name 'PowerShellGet' -PassThru -ErrorAction 'SilentlyContinue').Version + # Ensure the module is loaded and retrieve the version you have. + $powerShellGetVersion = (Import-Module -Name 'PowerShellGet' -PassThru -ErrorAction 'SilentlyContinue').Version - Write-Verbose -Message "Bootstrap: The PowerShellGet version is $powerShellGetVersion" + Write-Verbose -Message "Bootstrap: The PowerShellGet version is $powerShellGetVersion" - # Versions below 2.0 are considered old, unreliable & not recommended - if (-not $powerShellGetVersion -or ($powerShellGetVersion -lt [System.Version] '2.0' -and -not $AllowOldPowerShellGetModule)) - { - Write-Progress -Activity 'Bootstrap:' -PercentComplete 40 -CurrentOperation 'Fetching newer version of PowerShellGet' - - # PowerShellGet module not found, installing or saving it. - if ($PSDependTarget -in 'CurrentUser', 'AllUsers') + # Versions below 2.0 are considered old, unreliable & not recommended + if (-not $powerShellGetVersion -or ($powerShellGetVersion -lt [System.Version] '2.0' -and -not $AllowOldPowerShellGetModule)) { - Write-Debug -Message "PowerShellGet module not found. Attempting to install from Gallery $Gallery." + Write-Progress -Activity 'Bootstrap:' -PercentComplete 40 -CurrentOperation 'Fetching newer version of PowerShellGet' - Write-Warning -Message "Installing PowerShellGet in $PSDependTarget Scope." + # PowerShellGet module not found, installing or saving it. + if ($PSDependTarget -in 'CurrentUser', 'AllUsers') + { + Write-Debug -Message "PowerShellGet module not found. Attempting to install from Gallery $Gallery." - $installPowerShellGetParameters = @{ - Name = 'PowerShellGet' - Force = $True - SkipPublisherCheck = $true - AllowClobber = $true - Scope = $Scope - Repository = $Gallery - } + Write-Warning -Message "Installing PowerShellGet in $PSDependTarget Scope." - switch ($PSBoundParameters.Keys) - { - 'Proxy' - { - $installPowerShellGetParameters.Add('Proxy', $Proxy) + $installPowerShellGetParameters = @{ + Name = 'PowerShellGet' + Force = $true + SkipPublisherCheck = $true + AllowClobber = $true + Scope = $Scope + Repository = $Gallery } - 'ProxyCredential' + switch ($PSBoundParameters.Keys) { - $installPowerShellGetParameters.Add('ProxyCredential', $ProxyCredential) + 'Proxy' + { + $installPowerShellGetParameters.Add('Proxy', $Proxy) + } + + 'ProxyCredential' + { + $installPowerShellGetParameters.Add('ProxyCredential', $ProxyCredential) + } + + 'GalleryCredential' + { + $installPowerShellGetParameters.Add('Credential', $GalleryCredential) + } } - 'GalleryCredential' - { - $installPowerShellGetParameters.Add('Credential', $GalleryCredential) + Write-Progress -Activity 'Bootstrap:' -PercentComplete 60 -CurrentOperation 'Installing newer version of PowerShellGet' + + Install-Module @installPowerShellGetParameters + } + else + { + Write-Debug -Message "PowerShellGet module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" + + $saveModuleParameters = @{ + Name = 'PowerShellGet' + Repository = $Gallery + Path = $PSDependTarget + Force = $true } + + Write-Progress -Activity 'Bootstrap:' -PercentComplete 60 -CurrentOperation "Saving PowerShellGet from $Gallery to $Scope" + + Save-Module @saveModuleParameters + } + + Write-Debug -Message 'Removing previous versions of PowerShellGet and PackageManagement from session' + + Get-Module -Name 'PowerShellGet' -All | Remove-Module -Force -ErrorAction 'SilentlyContinue' + Get-Module -Name 'PackageManagement' -All | Remove-Module -Force + + Write-Progress -Activity 'Bootstrap:' -PercentComplete 65 -CurrentOperation 'Loading latest version of PowerShellGet' + + Write-Debug -Message 'Importing latest PowerShellGet and PackageManagement versions into session' + + if ($AllowOldPowerShellGetModule) + { + $powerShellGetModule = Import-Module -Name 'PowerShellGet' -Force -PassThru + } + else + { + Import-Module -Name 'PackageManagement' -MinimumVersion '1.4.8.1' -Force + + $powerShellGetModule = Import-Module -Name 'PowerShellGet' -MinimumVersion '2.2.5' -Force -PassThru } - Write-Progress -Activity 'Bootstrap:' -PercentComplete 60 -CurrentOperation 'Installing newer version of PowerShellGet' + $powerShellGetVersion = $powerShellGetModule.Version.ToString() - Install-Module @installPowerShellGetParameters + Write-Information -MessageData "Bootstrap: PowerShellGet version loaded is $powerShellGetVersion" } - else + } + + if (-not $UseModuleFast.IsPresent) + { + # Try to import the PSDepend module from the available modules. + $getModuleParameters = @{ + Name = 'PSDepend' + ListAvailable = $true + } + + $psDependModule = Get-Module @getModuleParameters + + if ($PSBoundParameters.ContainsKey('MinimumPSDependVersion')) { - Write-Debug -Message "PowerShellGet module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" - - $saveModuleParameters = @{ - Name = 'PowerShellGet' - MaximumVersion = '2.99.99' - Repository = $Gallery - Path = $PSDependTarget - Force = $true + try + { + $psDependModule = $psDependModule | Where-Object -FilterScript { $_.Version -ge $MinimumPSDependVersion } + } + catch + { + throw ('There was a problem finding the minimum version of PSDepend. Error: {0}' -f $_) } + } - Write-Progress -Activity 'Bootstrap:' -PercentComplete 60 -CurrentOperation "Saving PowerShellGet from $Gallery to $Scope" + if (-not $psDependModule) + { + Write-Debug -Message 'PSDepend module not found.' - Save-Module @saveModuleParameters - } + # PSDepend module not found, installing or saving it. + if ($PSDependTarget -in 'CurrentUser', 'AllUsers') + { + Write-Debug -Message "Attempting to install from Gallery '$Gallery'." - Write-Debug -Message 'Removing previous versions of PowerShellGet and PackageManagement from session' + Write-Warning -Message "Installing PSDepend in $PSDependTarget Scope." - Get-Module -Name 'PowerShellGet' -All | Remove-Module -Force -ErrorAction 'SilentlyContinue' - Get-Module -Name 'PackageManagement' -All | Remove-Module -Force + $installPSDependParameters = @{ + Name = 'PSDepend' + Repository = $Gallery + Force = $true + Scope = $PSDependTarget + SkipPublisherCheck = $true + AllowClobber = $true + } - Write-Progress -Activity 'Bootstrap:' -PercentComplete 65 -CurrentOperation 'Loading latest version of PowerShellGet' + if ($MinimumPSDependVersion) + { + $installPSDependParameters.Add('MinimumVersion', $MinimumPSDependVersion) + } - Write-Debug -Message 'Importing latest PowerShellGet and PackageManagement versions into session' + Write-Progress -Activity 'Bootstrap:' -PercentComplete 75 -CurrentOperation "Installing PSDepend from $Gallery" - Import-Module -Name 'PackageManagement' -MinimumVersion '1.4.8.1' -Force + Install-Module @installPSDependParameters + } + else + { + Write-Debug -Message "Attempting to Save from Gallery $Gallery to $PSDependTarget" - $powerShellGetModule = Import-Module -Name 'PowerShellGet' -MinimumVersion '2.2.5' -Force -PassThru + $saveModuleParameters = @{ + Name = 'PSDepend' + Repository = $Gallery + Path = $PSDependTarget + Force = $true + } - $powerShellGetVersion = $powerShellGetModule.Version.ToString() + if ($MinimumPSDependVersion) + { + $saveModuleParameters.add('MinimumVersion', $MinimumPSDependVersion) + } - Write-Information -MessageData "Bootstrap: PowerShellGet version loaded is $powerShellGetVersion" -InformationAction 'Continue' - } + Write-Progress -Activity 'Bootstrap:' -PercentComplete 75 -CurrentOperation "Saving PSDepend from $Gallery to $PSDependTarget" - # Try to import the PSDepend module from the available modules. - $getModuleParameters = @{ - Name = 'PSDepend' - ListAvailable = $true - } + Save-Module @saveModuleParameters + } + } - $psDependModule = Get-Module @getModuleParameters + Write-Progress -Activity 'Bootstrap:' -PercentComplete 80 -CurrentOperation 'Importing PSDepend' - if ($PSBoundParameters.ContainsKey('MinimumPSDependVersion')) - { - try - { - $psDependModule = $psDependModule | Where-Object -FilterScript { $_.Version -ge $MinimumPSDependVersion } + $importModulePSDependParameters = @{ + Name = 'PSDepend' + ErrorAction = 'Stop' + Force = $true } - catch + + if ($PSBoundParameters.ContainsKey('MinimumPSDependVersion')) { - throw ('There was a problem finding the minimum version of PSDepend. Error: {0}' -f $_) + $importModulePSDependParameters.Add('MinimumVersion', $MinimumPSDependVersion) } + + # We should have successfully bootstrapped PSDepend. Fail if not available. + $null = Import-Module @importModulePSDependParameters + + Write-Progress -Activity 'Bootstrap:' -PercentComplete 81 -CurrentOperation 'Invoke PSDepend' } - if (-not $psDependModule) + if (-not $UseModuleFast.IsPresent) { - # PSDepend module not found, installing or saving it. - if ($PSDependTarget -in 'CurrentUser', 'AllUsers') + if ($WithYAML) { - Write-Debug -Message "PSDepend module not found. Attempting to install from Gallery $Gallery." + Write-Progress -Activity 'Bootstrap:' -PercentComplete 82 -CurrentOperation 'Verifying PowerShell module PowerShell-Yaml' - Write-Warning -Message "Installing PSDepend in $PSDependTarget Scope." + if (-not (Get-Module -ListAvailable -Name 'PowerShell-Yaml')) + { + Write-Progress -Activity 'Bootstrap:' -PercentComplete 85 -CurrentOperation 'PowerShell-Yaml module not found. Installing PowerShell module PowerShell-Yaml' - $installPSDependParameters = @{ - Name = 'PSDepend' - Repository = $Gallery - Force = $true - Scope = $PSDependTarget - SkipPublisherCheck = $true - AllowClobber = $true - } + Write-Verbose -Message "Attempting to Save from Gallery '$Gallery' to '$PSDependTarget'." + + $SaveModuleParam = @{ + Name = 'PowerShell-Yaml' + Repository = $Gallery + Path = $PSDependTarget + Force = $true + } - if ($MinimumPSDependVersion) + Save-Module @SaveModuleParam + } + else { - $installPSDependParameters.Add('MinimumVersion', $MinimumPSDependVersion) + Write-Verbose -Message 'PowerShell-Yaml is already available' } - Write-Progress -Activity 'Bootstrap:' -PercentComplete 75 -CurrentOperation "Installing PSDepend from $Gallery" - - Install-Module @installPSDependParameters + Write-Progress -Activity 'Bootstrap:' -PercentComplete 88 -CurrentOperation 'Importing PowerShell module PowerShell-Yaml' } - else + } + + if (Test-Path -Path $DependencyFile) + { + if ($UseModuleFast.IsPresent) { - Write-Debug -Message "PSDepend module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" + Write-Progress -Activity 'Bootstrap:' -PercentComplete 90 -CurrentOperation 'Invoking ModuleFast' + + Write-Progress -Activity 'ModuleFast:' -PercentComplete 0 -CurrentOperation 'Restoring Build Dependencies' - $saveModuleParameters = @{ - Name = 'PSDepend' - Repository = $Gallery - Path = $PSDependTarget - Force = $true + $requiredModules = Import-PowerShellDataFile -Path $DependencyFile + + $requiredModules = $requiredModules.GetEnumerator() | + Where-Object -FilterScript { $_.Name -ne 'PSDependOptions' } + + $modulesToSave = @( + 'PSDepend' # Always include PSDepend for backward compatibility. + ) + + foreach ($requiredModule in $requiredModules) + { + if ($requiredModule.Value -eq 'latest') + { + $modulesToSave += $requiredModule.Name + } + else + { + $modulesToSave += @{ + ModuleName = $requiredModule.Name + RequiredVersion = $requiredModule.Value + } + } } - if ($MinimumPSDependVersion) + if ($WithYAML) { - $saveModuleParameters.add('MinimumVersion', $MinimumPSDependVersion) + $modulesToSave += 'PowerShell-Yaml' } - Write-Progress -Activity 'Bootstrap:' -PercentComplete 75 -CurrentOperation "Saving PSDepend from $Gallery to $Scope" + $moduleFastPlan = $modulesToSave | Get-ModuleFastPlan + + if ($moduleFastPlan) + { + # Clear all modules in plan from the current session so they can be fetched again. + $moduleFastPlan.Name | Get-Module | Remove-Module -Force + + $installModuleFastParameters = @{ + ModulesToInstall = $moduleFastPlan + Destination = $PSDependTarget + NoPSModulePathUpdate = $true + NoProfileUpdate = $true + Update = $true + Confirm = $false + } - Save-Module @saveModuleParameters + Install-ModuleFast @installModuleFastParameters + } + else + { + Write-Verbose -Message 'All modules were already up to date' + } + + Write-Progress -Activity 'ModuleFast:' -PercentComplete 100 -CurrentOperation 'Dependencies restored' -Completed } - } + else + { + Write-Progress -Activity 'Bootstrap:' -PercentComplete 90 -CurrentOperation 'Invoking PSDepend' + + Write-Progress -Activity 'PSDepend:' -PercentComplete 0 -CurrentOperation 'Restoring Build Dependencies' - Write-Progress -Activity 'Bootstrap:' -PercentComplete 80 -CurrentOperation 'Loading PSDepend' + $psDependParameters = @{ + Force = $true + Path = $DependencyFile + } + + # TODO: Handle when the Dependency file is in YAML, and -WithYAML is specified. + Invoke-PSDepend @psDependParameters - $importModulePSDependParameters = @{ - Name = 'PSDepend' - ErrorAction = 'Stop' - Force = $true + Write-Progress -Activity 'PSDepend:' -PercentComplete 100 -CurrentOperation 'Dependencies restored' -Completed + } } - if ($PSBoundParameters.ContainsKey('MinimumPSDependVersion')) + Write-Progress -Activity 'Bootstrap:' -PercentComplete 100 -CurrentOperation 'Bootstrap complete' -Completed +} +finally +{ + if ($RegisterGallery) { - $importModulePSDependParameters.Add('MinimumVersion', $MinimumPSDependVersion) + Write-Verbose -Message "Removing private package repository '$Gallery'." + Unregister-PSRepository -Name $Gallery } - # We should have successfully bootstrapped PSDepend. Fail if not available. - $null = Import-Module @importModulePSDependParameters - - if ($WithYAML) + if ($unregisteredPreviousRepository) { - Write-Progress -Activity 'Bootstrap:' -PercentComplete 82 -CurrentOperation 'Verifying PowerShell module PowerShell-Yaml' + Write-Verbose -Message "Reverting private package repository '$Gallery' to previous location URI:s." - if (-not (Get-Module -ListAvailable -Name 'PowerShell-Yaml')) - { - Write-Progress -Activity 'Bootstrap:' -PercentComplete 85 -CurrentOperation 'Installing PowerShell module PowerShell-Yaml' - - Write-Verbose -Message "PowerShell-Yaml module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" + $registerPSRepositoryParameters = @{ + Name = $previousRegisteredRepository.Name + InstallationPolicy = $previousRegisteredRepository.InstallationPolicy + } - $SaveModuleParam = @{ - Name = 'PowerShell-Yaml' - Repository = $Gallery - Path = $PSDependTarget - Force = $true - } + if ($previousRegisteredRepository.SourceLocation) + { + $registerPSRepositoryParameters.SourceLocation = $previousRegisteredRepository.SourceLocation + } - Save-Module @SaveModuleParam + if ($previousRegisteredRepository.PublishLocation) + { + $registerPSRepositoryParameters.PublishLocation = $previousRegisteredRepository.PublishLocation } - else + + if ($previousRegisteredRepository.ScriptSourceLocation) { - Write-Verbose 'PowerShell-Yaml is already available' + $registerPSRepositoryParameters.ScriptSourceLocation = $previousRegisteredRepository.ScriptSourceLocation } - Write-Progress -Activity 'Bootstrap:' -PercentComplete 88 -CurrentOperation 'Importing PowerShell module PowerShell-Yaml' + if ($previousRegisteredRepository.ScriptPublishLocation) + { + $registerPSRepositoryParameters.ScriptPublishLocation = $previousRegisteredRepository.ScriptPublishLocation + } - Import-Module -Name 'PowerShell-Yaml' -ErrorAction 'Stop' + Register-PSRepository @registerPSRepositoryParameters } - Write-Progress -Activity 'Bootstrap:' -PercentComplete 90 -CurrentOperation 'Invoke PSDepend' - - Write-Progress -Activity 'PSDepend:' -PercentComplete 0 -CurrentOperation 'Restoring Build Dependencies' - - if (Test-Path -Path $DependencyFile) + # Only try to revert installation policy if the repository exist + if ((Get-PSRepository -Name $Gallery -ErrorAction 'SilentlyContinue')) { - $psDependParameters = @{ - Force = $true - Path = $DependencyFile + if ($previousGalleryInstallationPolicy -and $previousGalleryInstallationPolicy -ne 'Trusted') + { + # Reverting the Installation Policy for the given gallery if it was not already trusted + Set-PSRepository -Name $Gallery -InstallationPolicy $previousGalleryInstallationPolicy } - - # TODO: Handle when the Dependency file is in YAML, and -WithYAML is specified. - Invoke-PSDepend @psDependParameters } - Write-Progress -Activity 'PSDepend:' -PercentComplete 100 -CurrentOperation 'Dependencies restored' -Completed - - Write-Progress -Activity 'Bootstrap:' -PercentComplete 100 -CurrentOperation 'Bootstrap complete' -Completed -} -finally -{ - # Reverting the Installation Policy for the given gallery - Set-PSRepository -Name $Gallery -InstallationPolicy $previousGalleryInstallationPolicy - - Write-Verbose -Message 'Project Bootstrapped, returning to Invoke-Build' + Write-Verbose -Message 'Project Bootstrapped, returning to Invoke-Build.' } diff --git a/build.ps1 b/build.ps1 index 19da5e4256..c5002fd8fc 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,6 +1,6 @@ <# .DESCRIPTION - Bootstrap and build script for PowerShell module CI/CD pipeline + Bootstrap and build script for PowerShell module CI/CD pipeline. .PARAMETER Tasks The task or tasks to run. The default value is '.' (runs the default task). @@ -56,6 +56,10 @@ .PARAMETER AutoRestore Not yet written. + + .PARAMETER UseModuleFast + Specifies to use ModuleFast instead of PowerShellGet to resolve dependencies + faster. #> [CmdletBinding()] param @@ -121,7 +125,11 @@ param [Parameter()] [System.Management.Automation.SwitchParameter] - $AutoRestore + $AutoRestore, + + [Parameter()] + [System.Management.Automation.SwitchParameter] + $UseModuleFast ) <# @@ -132,7 +140,6 @@ param process { - if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1') { # Only run the process block through InvokeBuild (look at the Begin block at the bottom of this script). @@ -178,7 +185,7 @@ process ConvertFrom-Yaml -Yaml (Get-Content -Raw $configFile) } - # Native Support for JSON and JSONC (by Removing comments) + # Support for JSON and JSONC (by Removing comments) when module PowerShell-Yaml is available '\.[json|jsonc]' { $jsonFile = Get-Content -Raw -Path $configFile @@ -336,7 +343,7 @@ process } } -Begin +begin { # Find build config if not specified. if (-not $BuildConfig) @@ -450,7 +457,15 @@ Begin if ($ResolveDependency) { - Write-Host -Object "[pre-build] Resolving dependencies." -ForegroundColor Green + if ($UseModuleFast.IsPresent) + { + Write-Host -Object "[pre-build] Resolving dependencies using ModuleFast." -ForegroundColor Green + } + else + { + Write-Host -Object "[pre-build] Resolving dependencies using PowerShellGet." -ForegroundColor Green + } + $resolveDependencyParams = @{ } # If BuildConfig is a Yaml file, bootstrap powershell-yaml via ResolveDependency. @@ -466,7 +481,7 @@ Begin # The parameter has been explicitly used for calling the .build.ps1 if ($MyInvocation.BoundParameters.ContainsKey($cmdParameter)) { - $paramValue = $MyInvocation.BoundParameters.ContainsKey($cmdParameter) + $paramValue = $MyInvocation.BoundParameters.Item($cmdParameter) Write-Debug " adding $cmdParameter :: $paramValue [from user-provided parameters to Build.ps1]" diff --git a/source/Examples/Resources/SqlRS/4-CompleteWithTwoInstances.ps1 b/source/Examples/Resources/SqlRS/4-CompleteWithTwoInstances.ps1 index a53da52594..b5d45ba9d1 100644 --- a/source/Examples/Resources/SqlRS/4-CompleteWithTwoInstances.ps1 +++ b/source/Examples/Resources/SqlRS/4-CompleteWithTwoInstances.ps1 @@ -42,12 +42,12 @@ Configuration Example $ReportingServicesServiceCredential ) - Import-DscResource -ModuleName PSDscResources -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' Import-DscResource -ModuleName 'SqlServerDsc' Node localhost { - WindowsFeature 'NetFramework45' + xWindowsFeature 'NetFramework45' { Name = 'NET-Framework-45-Core' Ensure = 'Present' diff --git a/source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1 b/source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1 index 99eb1f09bf..5ef7f271e6 100644 --- a/source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1 +++ b/source/Examples/Resources/SqlScript/3-RunScriptCompleteExample.ps1 @@ -54,12 +54,12 @@ Configuration Example $SqlAdministratorCredential ) - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' Import-DscResource -ModuleName 'SqlServerDsc' node localhost { - Script 'CreateFile_GetSqlScript' + xScript 'CreateFile_GetSqlScript' { SetScript = { $Using:Node.GetSqlScript | Out-File -FilePath $Using:Node.GetSqlScriptPath -Encoding ascii -NoClobber -Force @@ -90,7 +90,7 @@ Configuration Example } } - Script 'CreateFile_TestSqlScript' + xScript 'CreateFile_TestSqlScript' { SetScript = { $Using:Node.TestSqlScript | Out-File -FilePath $Using:Node.TestSqlScriptPath -Encoding ascii -NoClobber -Force diff --git a/source/Examples/Resources/SqlScriptQuery/3-RunScriptCompleteExample.ps1 b/source/Examples/Resources/SqlScriptQuery/3-RunScriptCompleteExample.ps1 index 260fafd5ea..3653f817dd 100644 --- a/source/Examples/Resources/SqlScriptQuery/3-RunScriptCompleteExample.ps1 +++ b/source/Examples/Resources/SqlScriptQuery/3-RunScriptCompleteExample.ps1 @@ -13,7 +13,6 @@ Configuration Example $SqlAdministratorCredential ) - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' Import-DscResource -ModuleName 'SqlServerDsc' node localhost diff --git a/tests/Integration/DSC_SqlAlwaysOnService.config.ps1 b/tests/Integration/DSC_SqlAlwaysOnService.config.ps1 index b8cdb96822..b4422701ed 100644 --- a/tests/Integration/DSC_SqlAlwaysOnService.config.ps1 +++ b/tests/Integration/DSC_SqlAlwaysOnService.config.ps1 @@ -70,18 +70,18 @@ else #> Configuration DSC_SqlAlwaysOnService_CreateDependencies_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' - Import-DscResource -ModuleName 'NetworkingDsc' -ModuleVersion '7.4.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' + Import-DscResource -ModuleName 'NetworkingDsc' -ModuleVersion '9.0.0' node $AllNodes.NodeName { - WindowsFeature 'AddFeatureFailoverClustering' + xWindowsFeature 'AddFeatureFailoverClustering' { Ensure = 'Present' Name = 'Failover-clustering' } - WindowsFeature 'AddFeatureFailoverClusteringPowerShellModule' + xWindowsFeature 'AddFeatureFailoverClusteringPowerShellModule' { Ensure = 'Present' Name = 'RSAT-Clustering-PowerShell' @@ -111,7 +111,7 @@ Configuration DSC_SqlAlwaysOnService_CreateDependencies_Config does not support administrative access point at this time. Issue https://github.com/PowerShell/xFailOverCluster/issues/147. #> - Script 'CreateActiveDirectoryDetachedCluster' + xScript 'CreateActiveDirectoryDetachedCluster' { SetScript = { $clusterStaticIpAddress = $Using:Node.ClusterStaticIpAddress @@ -198,7 +198,7 @@ Configuration DSC_SqlAlwaysOnService_CreateDependencies_Config #> Configuration DSC_SqlAlwaysOnService_CleanupDependencies_Config { - Import-DscResource -ModuleName 'NetworkingDsc' -ModuleVersion '7.4.0.0' + Import-DscResource -ModuleName 'NetworkingDsc' -ModuleVersion '9.0.0' node $AllNodes.NodeName { diff --git a/tests/Integration/DSC_SqlLogin.config.ps1 b/tests/Integration/DSC_SqlLogin.config.ps1 index e3dc807091..cb2393c73a 100644 --- a/tests/Integration/DSC_SqlLogin.config.ps1 +++ b/tests/Integration/DSC_SqlLogin.config.ps1 @@ -66,12 +66,12 @@ else #> Configuration DSC_SqlLogin_CreateDependencies_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' Import-DscResource -ModuleName 'SqlServerDsc' node $AllNodes.NodeName { - User 'CreateDscUser1' + xUser 'CreateDscUser1' { Ensure = 'Present' UserName = Split-Path -Path $Node.DscUser1Name -Leaf @@ -81,7 +81,7 @@ Configuration DSC_SqlLogin_CreateDependencies_Config -ArgumentList @($Node.Admin_UserName, (ConvertTo-SecureString -String $Node.Admin_Password -AsPlainText -Force)) } - User 'CreateDscUser2' + xUser 'CreateDscUser2' { Ensure = 'Present' UserName = Split-Path -Path $Node.DscUser2Name -Leaf @@ -91,7 +91,7 @@ Configuration DSC_SqlLogin_CreateDependencies_Config -ArgumentList @($Node.Admin_UserName, (ConvertTo-SecureString -String $Node.Admin_Password -AsPlainText -Force)) } - User 'CreateDscUser3' + xUser 'CreateDscUser3' { Ensure = 'Present' UserName = Split-Path -Path $Node.DscUser3Name -Leaf @@ -101,7 +101,7 @@ Configuration DSC_SqlLogin_CreateDependencies_Config -ArgumentList @($Node.Admin_UserName, (ConvertTo-SecureString -String $Node.Admin_Password -AsPlainText -Force)) } - Group 'CreateDscSqlUsers1' + xGroup 'CreateDscSqlUsers1' { Ensure = 'Present' GroupName = 'DscSqlUsers1' diff --git a/tests/Integration/DSC_SqlRS.config.ps1 b/tests/Integration/DSC_SqlRS.config.ps1 index 04aa7072c6..c3e367d998 100644 --- a/tests/Integration/DSC_SqlRS.config.ps1 +++ b/tests/Integration/DSC_SqlRS.config.ps1 @@ -76,8 +76,8 @@ else #> Configuration DSC_SqlRS_CreateDependencies_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' - Import-DscResource -ModuleName 'StorageDsc' -ModuleVersion '4.9.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' + Import-DscResource -ModuleName 'StorageDsc' -ModuleVersion '5.1.0' Import-DscResource -ModuleName 'WSManDsc' -ModuleVersion '3.1.1' Import-DscResource -ModuleName 'SqlServerDsc' @@ -89,7 +89,7 @@ Configuration DSC_SqlRS_CreateDependencies_Config MaxEnvelopeSizeKb = 600 } - User 'CreateReportingServicesServiceAccount' + xUser 'CreateReportingServicesServiceAccount' { Ensure = 'Present' UserName = Split-Path -Path $Node.Service_UserName -Leaf @@ -98,7 +98,7 @@ Configuration DSC_SqlRS_CreateDependencies_Config -ArgumentList @($Node.Service_UserName, (ConvertTo-SecureString -String $Node.Service_Password -AsPlainText -Force)) } - WindowsFeature 'NetFramework45' + xWindowsFeature 'NetFramework45' { Name = 'NET-Framework-45-Core' Ensure = 'Present' @@ -153,7 +153,7 @@ Configuration DSC_SqlRS_CreateDependencies_Config #> elseif ($script:sqlVersion -in @('140', '150', '160')) { - Service 'StartReportingServicesInstance' + xService 'StartReportingServicesInstance' { Name = 'SQLServerReportingServices' State = 'Running' @@ -201,13 +201,13 @@ Configuration DSC_SqlRS_ConfigureReportingServices_Config #> Configuration DSC_SqlRS_StopReportingServicesInstance_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { if ($script:sqlVersion -eq '130') { - Service ('StopReportingServicesInstance{0}' -f $Node.InstanceName) + xService ('StopReportingServicesInstance{0}' -f $Node.InstanceName) { Name = ('ReportServer${0}' -f $Node.InstanceName) State = 'Stopped' @@ -215,7 +215,7 @@ Configuration DSC_SqlRS_StopReportingServicesInstance_Config } elseif ($script:sqlVersion -in @('140', '150', '160')) { - Service 'StopReportingServicesInstance' + xService 'StopReportingServicesInstance' { Name = 'SQLServerReportingServices' State = 'Stopped' diff --git a/tests/Integration/DSC_SqlRSSetup.config.ps1 b/tests/Integration/DSC_SqlRSSetup.config.ps1 index 6c16b35e7f..77715fde86 100644 --- a/tests/Integration/DSC_SqlRSSetup.config.ps1 +++ b/tests/Integration/DSC_SqlRSSetup.config.ps1 @@ -77,11 +77,11 @@ Configuration DSC_SqlRSSetup_InstallReportingServicesAsUser_Config #> Configuration DSC_SqlRSSetup_StopReportingServicesInstance_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { - Service 'StopReportingServicesInstance' + xService 'StopReportingServicesInstance' { Name = 'SQLServerReportingServices' State = 'Stopped' diff --git a/tests/Integration/DSC_SqlRS_Default.config.ps1 b/tests/Integration/DSC_SqlRS_Default.config.ps1 index d31a72fc33..bf5d2e948e 100644 --- a/tests/Integration/DSC_SqlRS_Default.config.ps1 +++ b/tests/Integration/DSC_SqlRS_Default.config.ps1 @@ -76,8 +76,8 @@ else #> Configuration DSC_SqlRS_CreateDependencies_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' - Import-DscResource -ModuleName 'StorageDsc' -ModuleVersion '4.9.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' + Import-DscResource -ModuleName 'StorageDsc' -ModuleVersion '5.1.0' Import-DscResource -ModuleName 'WSManDsc' -ModuleVersion '3.1.1' Import-DscResource -ModuleName 'SqlServerDsc' @@ -89,7 +89,7 @@ Configuration DSC_SqlRS_CreateDependencies_Config MaxEnvelopeSizeKb = 600 } - User 'CreateReportingServicesServiceAccount' + xUser 'CreateReportingServicesServiceAccount' { Ensure = 'Present' UserName = Split-Path -Path $Node.Service_UserName -Leaf @@ -98,7 +98,7 @@ Configuration DSC_SqlRS_CreateDependencies_Config -ArgumentList @($Node.Service_UserName, (ConvertTo-SecureString -String $Node.Service_Password -AsPlainText -Force)) } - WindowsFeature 'NetFramework45' + xWindowsFeature 'NetFramework45' { Name = 'NET-Framework-45-Core' Ensure = 'Present' @@ -153,7 +153,7 @@ Configuration DSC_SqlRS_CreateDependencies_Config #> elseif ($script:sqlVersion -in @('140', '150', '160')) { - Service 'StartReportingServicesInstance' + xService 'StartReportingServicesInstance' { Name = 'SQLServerReportingServices' State = 'Running' @@ -263,13 +263,13 @@ Configuration DSC_SqlRS_RestoreToNoSsl_Config #> Configuration DSC_SqlRS_StopReportingServicesInstance_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { if ($script:sqlVersion -eq '130') { - Service ('StopReportingServicesInstance{0}' -f $Node.InstanceName) + xService ('StopReportingServicesInstance{0}' -f $Node.InstanceName) { Name = ('ReportServer${0}' -f $Node.InstanceName) State = 'Stopped' @@ -277,7 +277,7 @@ Configuration DSC_SqlRS_StopReportingServicesInstance_Config } elseif ($script:sqlVersion -in @('140', '150', '160')) { - Service 'StopReportingServicesInstance' + xService 'StopReportingServicesInstance' { Name = 'SQLServerReportingServices' State = 'Stopped' diff --git a/tests/Integration/DSC_SqlReplication.config.ps1 b/tests/Integration/DSC_SqlReplication.config.ps1 index 80d10f87f1..5484af38e1 100644 --- a/tests/Integration/DSC_SqlReplication.config.ps1 +++ b/tests/Integration/DSC_SqlReplication.config.ps1 @@ -36,17 +36,17 @@ else #> Configuration DSC_SqlReplication_Prerequisites_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { - Service ('StopSqlServerInstance{0}' -f $Node.DefaultInstanceName) + xService ('StopSqlServerInstance{0}' -f $Node.DefaultInstanceName) { Name = $Node.DefaultInstanceName State = 'Running' } - Service ('StopSqlServerAgentForInstance{0}' -f $Node.DefaultInstanceName) + xService ('StopSqlServerAgentForInstance{0}' -f $Node.DefaultInstanceName) { Name = 'SQLSERVERAGENT' State = 'Running' @@ -213,7 +213,7 @@ Configuration DSC_SqlReplication_RemoveDistributor_Config Configuration DSC_SqlReplication_Cleanup_Config { Import-DscResource -ModuleName 'SqlServerDsc' - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { @@ -241,13 +241,13 @@ Configuration DSC_SqlReplication_Cleanup_Config -ArgumentList @($Node.Username, (ConvertTo-SecureString -String $Node.Password -AsPlainText -Force)) } - Service ('StopSqlServerAgentForInstance{0}' -f $Node.DefaultInstanceName) + xService ('StopSqlServerAgentForInstance{0}' -f $Node.DefaultInstanceName) { Name = 'SQLSERVERAGENT' State = 'Stopped' } - Service ('StopSqlServerInstance{0}' -f $Node.DefaultInstanceName) + xService ('StopSqlServerInstance{0}' -f $Node.DefaultInstanceName) { Name = $Node.DefaultInstanceName State = 'Stopped' diff --git a/tests/Integration/DSC_SqlScript.config.ps1 b/tests/Integration/DSC_SqlScript.config.ps1 index ca45194529..2ae000aa5b 100644 --- a/tests/Integration/DSC_SqlScript.config.ps1 +++ b/tests/Integration/DSC_SqlScript.config.ps1 @@ -67,12 +67,12 @@ CREATE DATABASE [$(DatabaseName)] #> Configuration DSC_SqlScript_CreateDependencies_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' Import-DscResource -ModuleName 'SqlServerDsc' node $AllNodes.NodeName { - Script 'CreateFile_GetSqlScript' + xScript 'CreateFile_GetSqlScript' { SetScript = { $Using:Node.GetSqlScript | Out-File -FilePath $Using:Node.GetSqlScriptPath -Encoding ascii -NoClobber -Force @@ -103,7 +103,7 @@ Configuration DSC_SqlScript_CreateDependencies_Config } } - Script 'CreateFile_TestSqlScript' + xScript 'CreateFile_TestSqlScript' { SetScript = { $Using:Node.TestSqlScript | Out-File -FilePath $Using:Node.TestSqlScriptPath -Encoding ascii -NoClobber -Force @@ -129,7 +129,7 @@ Configuration DSC_SqlScript_CreateDependencies_Config } } - Script 'CreateFile_SetSqlScript' + xScript 'CreateFile_SetSqlScript' { SetScript = { $Using:Node.SetSqlScript | Out-File -FilePath $Using:Node.SetSqlScriptPath -Encoding ascii -NoClobber -Force diff --git a/tests/Integration/DSC_SqlServiceAccount.config.ps1 b/tests/Integration/DSC_SqlServiceAccount.config.ps1 index 42845ed4ea..9b5ba6ff6b 100644 --- a/tests/Integration/DSC_SqlServiceAccount.config.ps1 +++ b/tests/Integration/DSC_SqlServiceAccount.config.ps1 @@ -50,17 +50,17 @@ else #> Configuration DSC_SqlServiceAccount_CreateDependencies_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { - Service ('StartSqlServerDefaultInstance{0}' -f $Node.DefaultInstanceName) + xService ('StartSqlServerDefaultInstance{0}' -f $Node.DefaultInstanceName) { Name = $Node.DefaultInstanceName State = 'Running' } - Service ('StartSqlServerAgentForInstance{0}' -f $Node.DefaultInstanceName) + xService ('StartSqlServerAgentForInstance{0}' -f $Node.DefaultInstanceName) { Name = 'SQLSERVERAGENT' State = 'Running' @@ -192,17 +192,17 @@ Configuration DSC_SqlServiceAccount_SqlServerAgent_DefaultInstance_Restore_Confi #> Configuration DSC_SqlServiceAccount_StopSqlServerDefaultInstance_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { - Service ('StopSqlServerAgentForInstance{0}' -f $Node.DefaultInstanceName) + xService ('StopSqlServerAgentForInstance{0}' -f $Node.DefaultInstanceName) { Name = 'SQLSERVERAGENT' State = 'Stopped' } - Service ('StopSqlServerDefaultInstance{0}' -f $Node.DefaultInstanceName) + xService ('StopSqlServerDefaultInstance{0}' -f $Node.DefaultInstanceName) { Name = $Node.DefaultInstanceName State = 'Stopped' diff --git a/tests/Integration/DSC_SqlSetup.config.ps1 b/tests/Integration/DSC_SqlSetup.config.ps1 index c746210c04..b2ffb4ff16 100644 --- a/tests/Integration/DSC_SqlSetup.config.ps1 +++ b/tests/Integration/DSC_SqlSetup.config.ps1 @@ -239,8 +239,8 @@ $SqlAgentServiceSecondaryCredential = New-Object ` #> Configuration DSC_SqlSetup_CreateDependencies_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' - Import-DscResource -ModuleName 'StorageDsc' -ModuleVersion '4.9.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' + Import-DscResource -ModuleName 'StorageDsc' -ModuleVersion '5.1.0' node $AllNodes.NodeName { @@ -258,56 +258,56 @@ Configuration DSC_SqlSetup_CreateDependencies_Config RetryCount = 10 } - User 'CreateSqlServicePrimaryAccount' + xUser 'CreateSqlServicePrimaryAccount' { Ensure = 'Present' UserName = Split-Path -Path $SqlServicePrimaryCredential.UserName -Leaf Password = $SqlServicePrimaryCredential } - User 'CreateSqlAgentServicePrimaryAccount' + xUser 'CreateSqlAgentServicePrimaryAccount' { Ensure = 'Present' UserName = Split-Path -Path $SqlAgentServicePrimaryCredential.UserName -Leaf Password = $SqlAgentServicePrimaryCredential } - User 'CreateSqlServiceSecondaryAccount' + xUser 'CreateSqlServiceSecondaryAccount' { Ensure = 'Present' UserName = Split-Path -Path $SqlServiceSecondaryCredential.UserName -Leaf Password = $SqlServicePrimaryCredential } - User 'CreateSqlAgentServiceSecondaryAccount' + xUser 'CreateSqlAgentServiceSecondaryAccount' { Ensure = 'Present' UserName = Split-Path -Path $SqlAgentServiceSecondaryCredential.UserName -Leaf Password = $SqlAgentServicePrimaryCredential } - User 'CreateSqlInstallAccount' + xUser 'CreateSqlInstallAccount' { Ensure = 'Present' UserName = Split-Path -Path $SqlInstallCredential.UserName -Leaf Password = $SqlInstallCredential } - Group 'AddSqlInstallAsAdministrator' + xGroup 'AddSqlInstallAsAdministrator' { Ensure = 'Present' GroupName = 'Administrators' MembersToInclude = Split-Path -Path $SqlInstallCredential.UserName -Leaf } - User 'CreateSqlAdminAccount' + xUser 'CreateSqlAdminAccount' { Ensure = 'Present' UserName = Split-Path -Path $SqlAdministratorCredential.UserName -Leaf Password = $SqlAdministratorCredential } - WindowsFeature 'NetFramework45' + xWindowsFeature 'NetFramework45' { Name = 'NET-Framework-45-Core' Ensure = 'Present' @@ -329,11 +329,11 @@ Configuration DSC_SqlSetup_CreateDependencies_Config #> Configuration DSC_SqlSetup_InstallSMOModule_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { - Script 'InstallPowerShellGet' + xScript 'InstallPowerShellGet' { SetScript = { # Make sure PSGallery is trusted. @@ -410,7 +410,7 @@ Configuration DSC_SqlSetup_InstallSMOModule_Config # Only set the environment variable for the LCM user only if the pipeline has it configured. if ($env:SMODefaultModuleName) { - Environment 'SetSMODefaultModuleName' + xEnvironment 'SetSMODefaultModuleName' { Name = 'SMODefaultModuleName' Value = $env:SMODefaultModuleName @@ -420,7 +420,7 @@ Configuration DSC_SqlSetup_InstallSMOModule_Config } } - Script 'InstallSMOModule' + xScript 'InstallSMOModule' { DependsOn = @( '[Script]InstallPowerShellGet' @@ -594,7 +594,7 @@ Configuration DSC_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config #> Configuration DSC_SqlSetup_StopServicesInstance_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { @@ -602,7 +602,7 @@ Configuration DSC_SqlSetup_StopServicesInstance_Config Stopping the SQL Server Agent service for the named instance. It will be restarted at the end of the tests. #> - Service ('StopSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + xService ('StopSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) { Name = ('SQLAGENT${0}' -f $Node.DatabaseEngineNamedInstanceName) State = 'Stopped' @@ -612,7 +612,7 @@ Configuration DSC_SqlSetup_StopServicesInstance_Config Stopping the Database Engine named instance. It will be restarted at the end of the tests. #> - Service ('StopSqlServerInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + xService ('StopSqlServerInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) { Name = ('MSSQL${0}' -f $Node.DatabaseEngineNamedInstanceName) State = 'Stopped' @@ -660,18 +660,18 @@ Configuration DSC_SqlSetup_InstallDatabaseEngineDefaultInstanceAsUser_Config #> Configuration DSC_SqlSetup_StopSqlServerDefaultInstance_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { - Service ('StopSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineDefaultInstanceName) + xService ('StopSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineDefaultInstanceName) { Name = 'SQLSERVERAGENT' State = 'Stopped' } - Service ('StopSqlServerInstance{0}' -f $Node.DatabaseEngineDefaultInstanceName) + xService ('StopSqlServerInstance{0}' -f $Node.DatabaseEngineDefaultInstanceName) { Name = $Node.DatabaseEngineDefaultInstanceName State = 'Stopped' @@ -720,11 +720,11 @@ Configuration DSC_SqlSetup_InstallMultiDimensionalAnalysisServicesAsSystem_Confi #> Configuration DSC_SqlSetup_StopMultiDimensionalAnalysisServices_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { - Service ('StopMultiDimensionalAnalysisServicesInstance{0}' -f $Node.AnalysisServicesMultiInstanceName) + xService ('StopMultiDimensionalAnalysisServicesInstance{0}' -f $Node.AnalysisServicesMultiInstanceName) { Name = ('MSOLAP${0}' -f $Node.AnalysisServicesMultiInstanceName) State = 'Stopped' @@ -774,11 +774,11 @@ Configuration DSC_SqlSetup_InstallTabularAnalysisServicesAsSystem_Config #> Configuration DSC_SqlSetup_StopTabularAnalysisServices_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { - Service ('StopTabularAnalysisServicesInstance{0}' -f $Node.AnalysisServicesTabularInstanceName) + xService ('StopTabularAnalysisServicesInstance{0}' -f $Node.AnalysisServicesTabularInstanceName) { Name = ('MSOLAP${0}' -f $Node.AnalysisServicesTabularInstanceName) State = 'Stopped' @@ -796,19 +796,19 @@ Configuration DSC_SqlSetup_StopTabularAnalysisServices_Config #> Configuration DSC_SqlSetup_StartServicesInstance_Config { - Import-DscResource -ModuleName 'PSDscResources' -ModuleVersion '2.12.0.0' + Import-DscResource -ModuleName 'xPSDesiredStateConfiguration' -ModuleVersion '9.1.0' node $AllNodes.NodeName { # Start the Database Engine named instance. - Service ('StartSqlServerInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + xService ('StartSqlServerInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) { Name = ('MSSQL${0}' -f $Node.DatabaseEngineNamedInstanceName) State = 'Running' } # Starting the SQL Server Agent service for the named instance. - Service ('StartSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) + xService ('StartSqlServerAgentForInstance{0}' -f $Node.DatabaseEngineNamedInstanceName) { Name = ('SQLAGENT${0}' -f $Node.DatabaseEngineNamedInstanceName) State = 'Running' diff --git a/tests/Integration/DSC_SqlWindowsFirewall.config.ps1 b/tests/Integration/DSC_SqlWindowsFirewall.config.ps1 index b26d65fe6d..464351ce3c 100644 --- a/tests/Integration/DSC_SqlWindowsFirewall.config.ps1 +++ b/tests/Integration/DSC_SqlWindowsFirewall.config.ps1 @@ -39,7 +39,7 @@ else #> Configuration DSC_SqlWindowsFirewall_CreateDependencies_Config { - Import-DscResource -ModuleName 'StorageDsc' -ModuleVersion '4.9.0.0' + Import-DscResource -ModuleName 'StorageDsc' -ModuleVersion '5.1.0' node $AllNodes.NodeName {