diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d5760b8..3f9765587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- SPFarm + - Updated to run cmdlet `Update-SPFlightsConfigFile` on SharePoint Subscription. + ## [5.4.0] - 2023-04-04 ### Fixed diff --git a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index 641e9ac35..c2ac6b926 100644 --- a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -474,6 +474,7 @@ function Set-TargetResource } $PSBoundParameters.SkipRegisterAsDistributedCacheHost = $SkipRegisterAsDistributedCacheHost + $supportsFlighting = $false if ($PSBoundParameters.ContainsKey("CentralAdministrationUrl")) { @@ -879,6 +880,7 @@ function Set-TargetResource Write-Verbose -Message ("Detected Version: SharePoint Server Subscription Edition - " + "configuring server as $($params.ServerRole)") $supportsSettingApplicationCredentialKey = $true + $supportsFlighting = $true } $executeArgs.Add("LocalServerRole", $params.ServerRole) } @@ -907,6 +909,7 @@ function Set-TargetResource Write-Verbose -Message ("Detected Version: SharePoint Server Subscription Edition - " + "configuring server as $($params.ServerRole)") $supportsSettingApplicationCredentialKey = $true + $supportsFlighting = $true } $executeArgs.Add("ServerRoleOptional", $true) } @@ -1095,6 +1098,18 @@ function Set-TargetResource } } + if ($supportsFlighting -eq $true) + { + $spRootRegKey = "hklm:SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\16.0" + $spsLocation = Get-SPDscRegistryKey -Key $spRootRegKey -Value "Location" + $flightsConfigJsonFile = Join-Path -Path $spsLocation -ChildPath "CONFIG\SPFlightRawConfig.json" + if ((Test-Path -Path $flightsConfigJsonFile -PathType Leaf) -eq $true) + { + Write-Verbose -Message "Starting Update-SPFlightsConfigFile" + Update-SPFlightsConfigFile -FilePath $flightsConfigJsonFile | Out-Null + } + } + # Run common tasks for a new server Write-Verbose -Message "Starting Install-SPHelpCollection" Install-SPHelpCollection -All | Out-Null diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 index 414383e6b..e041bafd9 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 @@ -33,7 +33,7 @@ function Invoke-TestSetup $script:testEnvironment = Initialize-TestEnvironment ` -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceFullName ` + -DscResourceName $script:DSCResourceFullName ` -ResourceType 'Mof' ` -TestType 'Unit' } @@ -109,6 +109,31 @@ try } return $returnVal } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return "Connection string example" + } + } + Mock -CommandName Test-Path { + if ($Path -eq "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\CONFIG\SPFlightRawConfig.json") + { + return $true + } + else + { + return $true + } + } + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16 -and + $Global:SPDscHelper.CurrentStubBuildNumber.Build -gt 13000) + { + Mock -CommandName Update-SPFlightsConfigFile -MockWith { } + } function Add-SPDscEvent { @@ -231,7 +256,16 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -281,7 +315,16 @@ try RunCentralAdmin = $false } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -330,7 +373,16 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -381,7 +433,16 @@ try RunCentralAdmin = $false } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -475,7 +536,16 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -558,7 +628,16 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { if ($global:SPDscConfigLockTriggered) @@ -623,10 +702,6 @@ try CentralAdministrationUrl = "https://admin.contoso.com" } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -738,10 +813,6 @@ try CentralAdministrationUrl = "http://localhost:8080" } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -841,10 +912,6 @@ try CentralAdministrationPort = 8080 } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -934,10 +1001,6 @@ try CentralAdministrationAuth = "Kerberos" } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -1075,10 +1138,6 @@ try CentralAdministrationAuth = "NTLM" } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -1215,10 +1274,6 @@ try CentralAdministrationPort = 80 } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -1358,10 +1413,6 @@ try CentralAdministrationPort = 443 } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -1500,7 +1551,16 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -1578,7 +1638,16 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -1657,10 +1726,6 @@ try CentralAdministrationPort = 443 } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -2265,7 +2330,16 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -2413,7 +2487,16 @@ try RunCentralAdmin = $false } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } + Mock -CommandName Get-SPDscRegistryKey -MockWith { + if ($Value -eq "Location") + { + return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16" + } + elseif ($Value -eq "dsn") + { + return $null + } + } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{