ps/Modules/Alkami.PowerShell.Configuration/Public/Test-ORBEnvironmentalVariables.ps1
2023-05-30 22:51:22 -07:00

42 lines
1.5 KiB
PowerShell

function Test-ORBEnvironmentalVariables {
<#
.SYNOPSIS
Checks to verify that the expected environmental variables are present
#>
[CmdletBinding()]
Param()
$logLead = (Get-LogLeadName);
$expectedVariables = @(
@{ "Name" = "POD";
"Description" = "This variable should be set to the name of the POD/Lane or Team Environment. The value must match other servers in the grouping exactly, including case.";
"ValidationRegex" = "[^\s]+";
"ValidationError" = "The value for this variable cannot be an empty string"
},
@{ "Name" = "ServerRole";
"Description" = "This variable should be set to either Web or App, depending on the function of the server";
"ValidationRegex" = "^(Web|App)$";
"ValidationError" = "The value for this variable must be either Web or App";
}
)
foreach ($envVariable in $expectedVariables) {
$existingVariable = [Environment]::GetEnvironmentVariable($envVariable.Name, "Machine")
if ([String]::IsNullOrEmpty($existingVariable)) {
Write-Warning ("$logLead : The enviornmental variable {0} was not found. {1}" -f $envVariable.Name, $envVariable.Description)
if ($null -ne $host) {
Set-ORBEnvironmentalVariables $envVariable
}
}
else {
Write-Output ("$logLead : Environmental variable {0} found with value {1}" -f $envVariable.Name, $existingVariable)
}
}
}