Persist per-machine welcome location
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user