From 929b58864796906181fcf4d7799192cdd2ffe0f5 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 17 Mar 2023 17:14:00 +0100 Subject: [PATCH 1/3] Fixing #1420 and #1422 --- CHANGELOG.md | 5 ++ .../MSFT_SPPublishServiceApplication.psm1 | 4 +- .../SharePointDsc.Util.psm1 | 55 ++++++++++--------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdff489cc..aa7cc8ce6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,9 +18,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Export + - Fixed issue where the export would not run on Subscription Edition - SPInstallPrereqs - Fix issue where a failed VC++ upgrade results in two versions being present, which the code didn't handle properly +- SPPublishServiceApplication + - Fixed issue where the Set method never did anything because it was checking incorrect + values - SPShellAdmins - Fix issue where Get-SPDatabase could not be found - SPUserProfileServiceApp diff --git a/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 b/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 index 0b8da1771..cb96a7ba5 100644 --- a/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 @@ -104,13 +104,13 @@ function Set-TargetResource throw $message } - if ($Ensure -eq "Present") + if ($params.Ensure -eq "Present") { Write-Verbose -Message "Publishing Service Application $Name" Publish-SPServiceApplication -Identity $serviceApp } - if ($Ensure -eq "Absent") + if ($params.Ensure -eq "Absent") { Write-Verbose -Message "Unpublishing Service Application $Name" Unpublish-SPServiceApplication -Identity $serviceApp diff --git a/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 b/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 index 8c7ad4900..53d0d7508 100644 --- a/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 @@ -374,7 +374,7 @@ function Get-SPDscFarmAccount [System.Reflection.BindingFlags]::Instance -bor ` [System.Reflection.BindingFlags]::NonPublic - $pw = $account.GetType().GetField("m_Password", $bindings).GetValue($account); + $pw = $account.GetType().GetField("m_Password", $bindings).GetValue($account) return New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $farmaccount, $pw.SecureStringValue @@ -533,18 +533,18 @@ function Get-SPDscServerPatchStatus $farm = Get-SPFarm $productVersions = [Microsoft.SharePoint.Administration.SPProductVersions]::GetProductVersions($farm) $server = Get-SPServer $env:COMPUTERNAME - $serverProductInfo = $productVersions.GetServerProductInfo($server.Id); + $serverProductInfo = $productVersions.GetServerProductInfo($server.Id) if ($null -ne $serverProductInfo) { - $statusType = $serverProductInfo.InstallStatus; + $statusType = $serverProductInfo.InstallStatus if ($statusType -ne 0) { - $statusType = $serverProductInfo.GetUpgradeStatus($farm, $server); + $statusType = $serverProductInfo.GetUpgradeStatus($farm, $server) } } else { - $statusType = [Microsoft.SharePoint.Administration.SPServerProductInfo+StatusType]::NoActionRequired; + $statusType = [Microsoft.SharePoint.Administration.SPServerProductInfo+StatusType]::NoActionRequired } return $statusType @@ -561,22 +561,22 @@ function Get-SPDscAllServersPatchStatus [array]$srvStatus = @() foreach ($server in $servers) { - $serverProductInfo = $productVersions.GetServerProductInfo($server.Id); + $serverProductInfo = $productVersions.GetServerProductInfo($server.Id) if ($null -ne $serverProductInfo) { - $statusType = $serverProductInfo.InstallStatus; + $statusType = $serverProductInfo.InstallStatus if ($statusType -ne 0) { - $statusType = $serverProductInfo.GetUpgradeStatus($farm, $server); + $statusType = $serverProductInfo.GetUpgradeStatus($farm, $server) } } else { - $statusType = [Microsoft.SharePoint.Administration.SPServerProductInfo+StatusType]::NoActionRequired; + $statusType = [Microsoft.SharePoint.Administration.SPServerProductInfo+StatusType]::NoActionRequired } $srvStatus += [PSCustomObject]@{ - Name = $server.Name + Name = $server.Name Status = $statusType } } @@ -1674,36 +1674,39 @@ function Export-SPConfiguration $Global:spFarmAccount = "" $sharePointSnapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.PowerShell" } - if ($null -ne $sharePointSnapin) + if ($null -eq $sharePointSnapin) { - if ($Quiet -or $ComponentsToExtract.Count -gt 0) + $sharePointModule = Get-Module SharePointServer -ListAvailable + if ($null -eq $sharePointModule) { - if ($StandAlone) + Write-Host -Object " - We couldn't detect a SharePoint installation on this machine. Please execute the SharePoint ReverseDSC script on an existing SharePoint server." -BackgroundColor Red -ForegroundColor Black + return + } + } + + if ($Quiet -or $ComponentsToExtract.Count -gt 0) + { + if ($StandAlone) + { + if ($DynamicCompilation) { - if ($DynamicCompilation) - { - Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -Standalone -DynamicCompilation -ProductKey $ProductKey -BinaryLocation $BinaryLocation - } - else - { - Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -Standalone -ProductKey $ProductKey -BinaryLocation $BinaryLocation - } + Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -Standalone -DynamicCompilation -ProductKey $ProductKey -BinaryLocation $BinaryLocation } else { - Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -ProductKey $ProductKey -BinaryLocation $BinaryLocation + Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -Standalone -ProductKey $ProductKey -BinaryLocation $BinaryLocation } } else { - [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null - [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null - DisplayGUI + Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -ProductKey $ProductKey -BinaryLocation $BinaryLocation } } else { - Write-Host -Object " - We couldn't detect a SharePoint installation on this machine. Please execute the SharePoint ReverseDSC script on an existing SharePoint server." -BackgroundColor Red -ForegroundColor Black + [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null + [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null + DisplayGUI } } From 250a7e4d3e69f94264a520e3fcdcf1c39cec525e Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 17 Mar 2023 17:14:00 +0100 Subject: [PATCH 2/3] Fixing #1420 and #1422 --- CHANGELOG.md | 5 ++ .../MSFT_SPPublishServiceApplication.psm1 | 4 +- .../SharePointDsc.Util.psm1 | 55 ++++++++++--------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88f376f8d..29281028f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,9 +24,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Export + - Fixed issue where the export would not run on Subscription Edition - SPInstallPrereqs - Fix issue where a failed VC++ upgrade results in two versions being present, which the code didn't handle properly +- SPPublishServiceApplication + - Fixed issue where the Set method never did anything because it was checking incorrect + values - SPShellAdmins - Fix issue where Get-SPDatabase could not be found - SPUserProfileServiceApp diff --git a/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 b/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 index 0b8da1771..cb96a7ba5 100644 --- a/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPPublishServiceApplication/MSFT_SPPublishServiceApplication.psm1 @@ -104,13 +104,13 @@ function Set-TargetResource throw $message } - if ($Ensure -eq "Present") + if ($params.Ensure -eq "Present") { Write-Verbose -Message "Publishing Service Application $Name" Publish-SPServiceApplication -Identity $serviceApp } - if ($Ensure -eq "Absent") + if ($params.Ensure -eq "Absent") { Write-Verbose -Message "Unpublishing Service Application $Name" Unpublish-SPServiceApplication -Identity $serviceApp diff --git a/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 b/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 index 8c7ad4900..53d0d7508 100644 --- a/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 +++ b/SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1 @@ -374,7 +374,7 @@ function Get-SPDscFarmAccount [System.Reflection.BindingFlags]::Instance -bor ` [System.Reflection.BindingFlags]::NonPublic - $pw = $account.GetType().GetField("m_Password", $bindings).GetValue($account); + $pw = $account.GetType().GetField("m_Password", $bindings).GetValue($account) return New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $farmaccount, $pw.SecureStringValue @@ -533,18 +533,18 @@ function Get-SPDscServerPatchStatus $farm = Get-SPFarm $productVersions = [Microsoft.SharePoint.Administration.SPProductVersions]::GetProductVersions($farm) $server = Get-SPServer $env:COMPUTERNAME - $serverProductInfo = $productVersions.GetServerProductInfo($server.Id); + $serverProductInfo = $productVersions.GetServerProductInfo($server.Id) if ($null -ne $serverProductInfo) { - $statusType = $serverProductInfo.InstallStatus; + $statusType = $serverProductInfo.InstallStatus if ($statusType -ne 0) { - $statusType = $serverProductInfo.GetUpgradeStatus($farm, $server); + $statusType = $serverProductInfo.GetUpgradeStatus($farm, $server) } } else { - $statusType = [Microsoft.SharePoint.Administration.SPServerProductInfo+StatusType]::NoActionRequired; + $statusType = [Microsoft.SharePoint.Administration.SPServerProductInfo+StatusType]::NoActionRequired } return $statusType @@ -561,22 +561,22 @@ function Get-SPDscAllServersPatchStatus [array]$srvStatus = @() foreach ($server in $servers) { - $serverProductInfo = $productVersions.GetServerProductInfo($server.Id); + $serverProductInfo = $productVersions.GetServerProductInfo($server.Id) if ($null -ne $serverProductInfo) { - $statusType = $serverProductInfo.InstallStatus; + $statusType = $serverProductInfo.InstallStatus if ($statusType -ne 0) { - $statusType = $serverProductInfo.GetUpgradeStatus($farm, $server); + $statusType = $serverProductInfo.GetUpgradeStatus($farm, $server) } } else { - $statusType = [Microsoft.SharePoint.Administration.SPServerProductInfo+StatusType]::NoActionRequired; + $statusType = [Microsoft.SharePoint.Administration.SPServerProductInfo+StatusType]::NoActionRequired } $srvStatus += [PSCustomObject]@{ - Name = $server.Name + Name = $server.Name Status = $statusType } } @@ -1674,36 +1674,39 @@ function Export-SPConfiguration $Global:spFarmAccount = "" $sharePointSnapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.PowerShell" } - if ($null -ne $sharePointSnapin) + if ($null -eq $sharePointSnapin) { - if ($Quiet -or $ComponentsToExtract.Count -gt 0) + $sharePointModule = Get-Module SharePointServer -ListAvailable + if ($null -eq $sharePointModule) { - if ($StandAlone) + Write-Host -Object " - We couldn't detect a SharePoint installation on this machine. Please execute the SharePoint ReverseDSC script on an existing SharePoint server." -BackgroundColor Red -ForegroundColor Black + return + } + } + + if ($Quiet -or $ComponentsToExtract.Count -gt 0) + { + if ($StandAlone) + { + if ($DynamicCompilation) { - if ($DynamicCompilation) - { - Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -Standalone -DynamicCompilation -ProductKey $ProductKey -BinaryLocation $BinaryLocation - } - else - { - Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -Standalone -ProductKey $ProductKey -BinaryLocation $BinaryLocation - } + Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -Standalone -DynamicCompilation -ProductKey $ProductKey -BinaryLocation $BinaryLocation } else { - Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -ProductKey $ProductKey -BinaryLocation $BinaryLocation + Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -Standalone -ProductKey $ProductKey -BinaryLocation $BinaryLocation } } else { - [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null - [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null - DisplayGUI + Get-SPReverseDSC -ComponentsToExtract $ComponentsToExtract -Credentials $Credentials -OutputPath $OutputPath -ProductKey $ProductKey -BinaryLocation $BinaryLocation } } else { - Write-Host -Object " - We couldn't detect a SharePoint installation on this machine. Please execute the SharePoint ReverseDSC script on an existing SharePoint server." -BackgroundColor Red -ForegroundColor Black + [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null + [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null + DisplayGUI } } From 4c961c7dcda3ad031b20bb9c1ea9121bac1eee89 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 17 Mar 2023 17:16:17 +0100 Subject: [PATCH 3/3] Corrected changelog --- CHANGELOG.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29281028f..e1f5a0b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Export + - Fixed issue where the export would not run on Subscription Edition - SPTrustedRootAuthority - Added `-Recurse` flag to `Get-ChildItem` when setting certificate by Thumbprint. +- SPPublishServiceApplication + - Fixed issue where the Set method never did anything because it was checking incorrect + values ## [5.3.0] - 2022-11-15 @@ -24,14 +31,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Export - - Fixed issue where the export would not run on Subscription Edition - SPInstallPrereqs - Fix issue where a failed VC++ upgrade results in two versions being present, which the code didn't handle properly -- SPPublishServiceApplication - - Fixed issue where the Set method never did anything because it was checking incorrect - values - SPShellAdmins - Fix issue where Get-SPDatabase could not be found - SPUserProfileServiceApp