Functions/Test-HaveDeploySettingsChangedSinceLastDeploy.ps1
|
<#
.SYNOPSIS Compares current deployment settings with previous settings to determine if they have changed. .DESCRIPTION The Test-HaveDeploySettingsChangedSinceLastDeploy function compares two settings objects by serializing them to JSON format and comparing the resulting strings. This is used to determine if a database redeployment is needed due to configuration changes. .PARAMETER OldSettings Specifies the previous deployment settings object to compare against. .PARAMETER Settings Specifies the current deployment settings object to compare. .OUTPUTS Boolean Returns $true if the settings have changed, $false otherwise. .EXAMPLE $oldSettings = @{ ServerName = "localhost"; DatabaseName = "MyDB" } $newSettings = @{ ServerName = "localhost"; DatabaseName = "MyDB2" } Test-HaveDeploySettingsChangedSinceLastDeploy -OldSettings $oldSettings -Settings $newSettings Returns $true because the DatabaseName has changed. .EXAMPLE $oldSettings = @{ ServerName = "localhost"; DatabaseName = "MyDB" } $newSettings = @{ ServerName = "localhost"; DatabaseName = "MyDB" } Test-HaveDeploySettingsChangedSinceLastDeploy -OldSettings $oldSettings -Settings $newSettings Returns $false because the settings are identical. .NOTES The comparison is performed by serializing both settings objects to JSON and comparing the strings. This provides a reliable way to detect any changes in the settings structure or values. #> Function Test-HaveDeploySettingsChangedSinceLastDeploy { [CmdletBinding()] param ( [Parameter( HelpMessage = "Previous deployment settings")] $OldSettings, [Parameter( HelpMessage = "Current deployment settings")] $Settings ) #Compares settings $OldSettingsJson = (Get-SettingsAsJson -settings $OldSettings ) Write-Verbose "OldSettings $($OldSettingsJson.Length)" Write-Verbose "$OldSettingsJson" $NewSettingsJson = (Get-SettingsAsJson -settings $Settings ) Write-Verbose "NewSettings $($NewSettingsJson.Length)" Write-Verbose "$NewSettingsJson" for ($i = 0; $i -lt $NewSettingsJson.Length; $i++) { #ToDO show whats changed } return $OldSettingsJson -ne $NewSettingsJson } |