From 351adb0bdc472625177a858ec6b9e8e7b2a07065 Mon Sep 17 00:00:00 2001 From: Alejandro Rosales Date: Thu, 17 Sep 2026 14:59:35 -0600 Subject: [PATCH] Persist per-machine welcome location --- docs/welcome-wallpaper.md | 5 +++++ scripts/Set-SguWelcomeWallpaper.ps1 | 24 ++++++++++++++++++++---- tests/WelcomeWallpaper.Tests.ps1 | 23 +++++++++++++++++++++-- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/docs/welcome-wallpaper.md b/docs/welcome-wallpaper.md index 35e9677..bb60c72 100644 --- a/docs/welcome-wallpaper.md +++ b/docs/welcome-wallpaper.md @@ -21,6 +21,11 @@ guardar credenciales. Obtiene: - `location` del objeto de equipo. - La OU padre inmediata a partir de `distinguishedName`. +Los valores de equipo `SGU_WELCOME_LOCATION` y +`SGU_WELCOME_ORGANIZATIONAL_UNIT` pueden fijar ambos datos en una máquina +concreta. Tienen prioridad sobre el directorio y sobreviven cuando la GPO +restaura el comando genérico de inicio. + El saludo usa `Bienvenido/ubicado` para `Male` y `Bienvenida/ubicada` para `Female`. Cuando el enriquecimiento no produjo este dato, utiliza la redacción neutral `Te damos la bienvenida` y `Ubicación:`. El texto secundario sigue estas diff --git a/scripts/Set-SguWelcomeWallpaper.ps1 b/scripts/Set-SguWelcomeWallpaper.ps1 index 9de52c1..070c8a5 100644 --- a/scripts/Set-SguWelcomeWallpaper.ps1 +++ b/scripts/Set-SguWelcomeWallpaper.ps1 @@ -305,6 +305,14 @@ if (-not (Test-Path -LiteralPath $BaseImagePath -PathType Leaf)) { $userName = [Environment]::UserName $metadata = $null +$machineLocation = [Environment]::GetEnvironmentVariable('SGU_WELCOME_LOCATION', 'Machine') +$machineOrganizationalUnit = [Environment]::GetEnvironmentVariable( + 'SGU_WELCOME_ORGANIZATIONAL_UNIT', + 'Machine') +if (-not $machineLocation) { $machineLocation = $env:SGU_WELCOME_LOCATION } +if (-not $machineOrganizationalUnit) { + $machineOrganizationalUnit = $env:SGU_WELCOME_ORGANIZATIONAL_UNIT +} if (-not $SkipDirectoryLookup) { try { $metadata = Get-DirectoryWelcomeMetadata -UserName $userName -MachineName $ComputerName @@ -320,8 +328,8 @@ if (-not $PSBoundParameters.ContainsKey('DisplayName')) { if (-not $DisplayName) { $DisplayName = $userName } -if (-not $PSBoundParameters.ContainsKey('Location') -and $metadata) { - $Location = $metadata.Location +if (-not $PSBoundParameters.ContainsKey('Location')) { + $Location = if ($machineLocation) { $machineLocation } elseif ($metadata) { $metadata.Location } else { $null } } $genderWasProvided = $PSBoundParameters.ContainsKey('Gender') if (-not $genderWasProvided -and $metadata -and $metadata.Gender -in @('Male', 'Female')) { @@ -330,8 +338,16 @@ if (-not $genderWasProvided -and $metadata -and $metadata.Gender -in @('Male', ' $Gender = $metadata.Gender } $welcomeHeading = Get-WelcomeHeading -Gender $Gender -if (-not $PSBoundParameters.ContainsKey('OrganizationalUnit') -and $metadata) { - $OrganizationalUnit = $metadata.OrganizationalUnit +if (-not $PSBoundParameters.ContainsKey('OrganizationalUnit')) { + $OrganizationalUnit = if ($machineOrganizationalUnit) { + $machineOrganizationalUnit + } + elseif ($metadata) { + $metadata.OrganizationalUnit + } + else { + $null + } } $locationText = Get-WelcomeLocationText -Room $Location -OuName $OrganizationalUnit -Gender $Gender diff --git a/tests/WelcomeWallpaper.Tests.ps1 b/tests/WelcomeWallpaper.Tests.ps1 index 6fe1755..72f9ef8 100644 --- a/tests/WelcomeWallpaper.Tests.ps1 +++ b/tests/WelcomeWallpaper.Tests.ps1 @@ -16,7 +16,9 @@ function Invoke-WelcomeFixture { $DirectoryGender, [string]$ExplicitGender, [string]$DirectoryLocation = 'Sala de pruebas', - [string]$DirectoryOu = 'Laboratorio' + [string]$DirectoryOu = 'Laboratorio', + [string]$MachineLocation, + [string]$MachineOu ) # Replace only the external directory lookup. Execute the actual script, @@ -43,11 +45,19 @@ function Invoke-WelcomeFixture { } if ($ExplicitGender) { $parameters.Gender = $ExplicitGender } $previousLocalAppData = $env:LOCALAPPDATA + $previousMachineLocation = $env:SGU_WELCOME_LOCATION + $previousMachineOu = $env:SGU_WELCOME_ORGANIZATIONAL_UNIT try { $env:LOCALAPPDATA = $TestDrive + $env:SGU_WELCOME_LOCATION = $MachineLocation + $env:SGU_WELCOME_ORGANIZATIONAL_UNIT = $MachineOu & $testScript @parameters } - finally { $env:LOCALAPPDATA = $previousLocalAppData } + finally { + $env:LOCALAPPDATA = $previousLocalAppData + $env:SGU_WELCOME_LOCATION = $previousMachineLocation + $env:SGU_WELCOME_ORGANIZATIONAL_UNIT = $previousMachineOu + } } Describe 'Welcome wallpaper with AD metadata' { @@ -81,4 +91,13 @@ Describe 'Welcome wallpaper with AD metadata' { -DirectoryOu 'Centro de Experiencia Digital' $result.LocationText | Should Be 'Acceso al Aula Flexible del Centro de Experiencia Digital.' } + + It 'keeps machine location metadata when the GPO command has no location arguments' { + $result = Invoke-WelcomeFixture -DirectoryGender $null ` + -DirectoryLocation 'Sala de pruebas' ` + -DirectoryOu 'Laboratorio' ` + -MachineLocation 'Aula Flexible' ` + -MachineOu 'Centro de Experiencia Digital' + $result.LocationText | Should Be 'Acceso al Aula Flexible del Centro de Experiencia Digital.' + } }