From 9e4c53bc556d85a641ef0fd318a52fc2f1cb8c99 Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Mon, 17 Apr 2023 11:42:48 +0200 Subject: [PATCH 1/6] Update MSFT_SPFarm.psm1 --- .../DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index 641e9ac35..ba82fd37a 100644 --- a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -106,6 +106,7 @@ function Get-TargetResource } $supportsSettingApplicationCredentialKey = $false + $supportsFlighting = $false $installedVersion = Get-SPDscInstalledProductVersion switch ($installedVersion.FileMajorPart) { @@ -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 $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 From e952ac589d2b16c717859f2e50ad1ff897f3b155 Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Mon, 17 Apr 2023 14:07:25 +0200 Subject: [PATCH 2/6] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) 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 From e2398f549f985634d138c9c444f653c246ab16b0 Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Mon, 17 Apr 2023 15:55:48 +0200 Subject: [PATCH 3/6] Update MSFT_SPFarm.psm1 --- SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index ba82fd37a..cb6156faa 100644 --- a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -106,7 +106,6 @@ function Get-TargetResource } $supportsSettingApplicationCredentialKey = $false - $supportsFlighting = $false $installedVersion = Get-SPDscInstalledProductVersion switch ($installedVersion.FileMajorPart) { @@ -475,6 +474,7 @@ function Set-TargetResource } $PSBoundParameters.SkipRegisterAsDistributedCacheHost = $SkipRegisterAsDistributedCacheHost + $supportsFlighting = $false if ($PSBoundParameters.ContainsKey("CentralAdministrationUrl")) { @@ -1103,7 +1103,7 @@ function Set-TargetResource $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 $flightsConfigJsonFile -PathType Leaf) -eq $true) + if ((Test-Path $flightsConfigJsonFile -PathType Leaf) -eq $true) { Write-Verbose -Message "Starting Update-SPFlightsConfigFile" Update-SPFlightsConfigFile -FilePath $flightsConfigJsonFile | Out-Null From 0e9a05bb9a7f00fba2a4d14ac573a29848218f8b Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Tue, 18 Apr 2023 10:59:25 +0200 Subject: [PATCH 4/6] update tests --- .../DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 | 2 +- .../SharePointDsc.SPFarm.Tests.ps1 | 65 +++++++------------ 2 files changed, 23 insertions(+), 44 deletions(-) diff --git a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index cb6156faa..c2ac6b926 100644 --- a/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -1103,7 +1103,7 @@ function Set-TargetResource $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 $flightsConfigJsonFile -PathType Leaf) -eq $true) + if ((Test-Path -Path $flightsConfigJsonFile -PathType Leaf) -eq $true) { Write-Verbose -Message "Starting Update-SPFlightsConfigFile" Update-SPFlightsConfigFile -FilePath $flightsConfigJsonFile | Out-Null diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 index 414383e6b..3a1642098 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 @@ -50,7 +50,7 @@ try InModuleScope -ModuleName $script:DSCResourceFullName -ScriptBlock { Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { - Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + Invoke-Command -Scriptblock $Global:SPDscHelper.InitializeScript -NoNewScope # Initialize tests $mockPassword = ConvertTo-SecureString -String 'password' -AsPlainText -Force @@ -109,6 +109,27 @@ try } return $returnVal } + Mock -CommandName Update-SPFlightsConfigFile -MockWith { } + 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 + } + } function Add-SPDscEvent { @@ -231,7 +252,6 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -281,7 +301,6 @@ try RunCentralAdmin = $false } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -330,7 +349,6 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -381,7 +399,6 @@ try RunCentralAdmin = $false } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -475,7 +492,6 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -558,7 +574,6 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { if ($global:SPDscConfigLockTriggered) @@ -623,10 +638,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 +749,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 +848,6 @@ try CentralAdministrationPort = 8080 } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -934,10 +937,6 @@ try CentralAdministrationAuth = "Kerberos" } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -1075,10 +1074,6 @@ try CentralAdministrationAuth = "NTLM" } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -1215,10 +1210,6 @@ try CentralAdministrationPort = 80 } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -1358,10 +1349,6 @@ try CentralAdministrationPort = 443 } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -1500,7 +1487,6 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -1578,7 +1564,6 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -1657,10 +1642,6 @@ try CentralAdministrationPort = 443 } - Mock -CommandName Get-SPDscRegistryKey -MockWith { - return "Connection string example" - } - Mock -CommandName Get-SPFarm -MockWith { return @{ Name = $testParams.FarmConfigDatabaseName @@ -2265,7 +2246,6 @@ try RunCentralAdmin = $true } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ @@ -2413,7 +2393,6 @@ try RunCentralAdmin = $false } - Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null } Mock -CommandName "Get-SPFarm" -MockWith { return $null } Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith { return @{ From e2a7878f9883631759bf093b448a178e89ea157f Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Thu, 20 Apr 2023 13:25:46 +0200 Subject: [PATCH 5/6] Update SharePointDsc.SPFarm.Tests.ps1 --- .../SharePointDsc.SPFarm.Tests.ps1 | 102 +++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 index 3a1642098..7c37dde7e 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' } @@ -252,6 +252,16 @@ try RunCentralAdmin = $true } + 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 @{ @@ -301,6 +311,16 @@ try RunCentralAdmin = $false } + 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 @{ @@ -349,6 +369,16 @@ try RunCentralAdmin = $true } + 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 @{ @@ -399,6 +429,16 @@ try RunCentralAdmin = $false } + 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 @{ @@ -492,6 +532,16 @@ try RunCentralAdmin = $true } + 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 @{ @@ -574,6 +624,16 @@ try RunCentralAdmin = $true } + 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) @@ -1487,6 +1547,16 @@ try RunCentralAdmin = $true } + 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 @{ @@ -1564,6 +1634,16 @@ try RunCentralAdmin = $true } + 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 @{ @@ -2246,6 +2326,16 @@ try RunCentralAdmin = $true } + 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 @{ @@ -2393,6 +2483,16 @@ try RunCentralAdmin = $false } + 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 @{ From 9d17ae84e4f8b8eaa2bd2974e662b7b388ec30a8 Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Fri, 21 Apr 2023 15:45:15 +0200 Subject: [PATCH 6/6] Update SharePointDsc.SPFarm.Tests.ps1 --- tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 index 7c37dde7e..e041bafd9 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 @@ -50,7 +50,7 @@ try InModuleScope -ModuleName $script:DSCResourceFullName -ScriptBlock { Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { - Invoke-Command -Scriptblock $Global:SPDscHelper.InitializeScript -NoNewScope + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope # Initialize tests $mockPassword = ConvertTo-SecureString -String 'password' -AsPlainText -Force @@ -109,7 +109,6 @@ try } return $returnVal } - Mock -CommandName Update-SPFlightsConfigFile -MockWith { } Mock -CommandName Get-SPDscRegistryKey -MockWith { if ($Value -eq "Location") { @@ -130,6 +129,11 @@ try return $true } } + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16 -and + $Global:SPDscHelper.CurrentStubBuildNumber.Build -gt 13000) + { + Mock -CommandName Update-SPFlightsConfigFile -MockWith { } + } function Add-SPDscEvent {