Consolidate laboratory network and client maintenance policies

This commit is contained in:
alexrg committed 2026-10-14 21:49:32 -06:00
1 parent bfa520dec8
commit 5cda541e3d
20 files changed
+534 -107

No files matched your search

+12 -40
View File
@@ -1,45 +1,17 @@
[CmdletBinding()]
param([switch]$InstallTask)
$ErrorActionPreference = 'Stop'
$directory = 'C:\ProgramData\LCI-Admin\CED-Client'
if ($InstallTask) {
New-Item $directory -ItemType Directory -Force | Out-Null
$acl = [Security.AccessControl.DirectorySecurity]::new()
$acl.SetAccessRuleProtection($true,$false)
foreach ($sid in 'S-1-5-18','S-1-5-32-544') {
$acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new(
[Security.Principal.SecurityIdentifier]::new($sid),'FullControl','ContainerInherit,ObjectInherit','None','Allow'))
}
Set-Acl $directory $acl
$localScript = Join-Path $directory 'Invoke-SguCedClientEnrollment.ps1'
if ($PSCommandPath -ine $localScript) { Copy-Item $PSCommandPath $localScript -Force }
$action = New-ScheduledTaskAction -Execute powershell.exe -Argument ('-NoProfile -NonInteractive -ExecutionPolicy Bypass -File "{0}"' -f $localScript)
$triggers = @((New-ScheduledTaskTrigger -AtStartup),(New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) -RepetitionInterval (New-TimeSpan -Minutes 30)))
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Minutes 5)
Register-ScheduledTask 'CED Configuration Manager policy enrollment' -Action $action -Trigger $triggers -Settings $settings -User SYSTEM -RunLevel Highest -Force | Out-Null
Start-ScheduledTask 'CED Configuration Manager policy enrollment'
$ErrorActionPreference='Stop'
# Compatibility entry point for cached WLAN startup registrations.
# The global SYSTEMCENTER GPO owns installation, repair and version selection.
$canonical=Get-ScheduledTask -TaskName 'LCI-ConfigMgr2509-ClientRegistration' -ErrorAction SilentlyContinue
if(-not $canonical -or -not $canonical.Settings.Enabled -or $canonical.Actions.Arguments -notmatch 'SYSTEMCENTER\.lci\.lasalle\.mx.+Ensure-CMCurrentClient\.ps1'){
Write-Warning 'Apply the global Configuration Manager policy with gpupdate /target:computer /force. The retired CED installer task is not recreated.'
return
}
if (Get-Service CcmExec -ErrorAction SilentlyContinue) { return }
if (Get-Process ccmsetup -ErrorAction SilentlyContinue) { return }
# Check the machine's current OU with its own domain identity. An offline DC
# defers enrollment; an existing Wi-Fi connection continues using its cached PSK.
$root = [ADSI]'LDAP://RootDSE'
$search = [DirectoryServices.DirectorySearcher]::new([ADSI]("LDAP://"+[string]$root.defaultNamingContext))
try {
$search.Filter = '(&(objectClass=computer)(sAMAccountName='+$env:COMPUTERNAME+'$))'
[void]$search.PropertiesToLoad.Add('distinguishedName')
$result = $search.FindOne()
$dn = [string]$result.Properties['distinguishedname'][0]
$ou = 'OU=Centro de Experiencia Digital,OU=Laboratorio,DC=lci,DC=lasalle,DC=mx'
if (-not $dn.EndsWith(','+$ou,[StringComparison]::OrdinalIgnoreCase)) { return }
} finally { $search.Dispose() }
$source = '\\sgu-dc02.lci.lasalle.mx\CEDClient$'
$bootstrap = Join-Path $source 'ccmsetup.exe'
$signature = Get-AuthenticodeSignature $bootstrap
if ($signature.Status -ne 'Valid' -or $signature.SignerCertificate.Subject -notlike '*Microsoft Corporation*') {
throw 'Client bootstrapper is not a valid Microsoft-signed binary.'
foreach($name in 'CED Configuration Manager enrollment','CED Configuration Manager policy enrollment'){
$old=Get-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue
if($old -and $old.Settings.Enabled -and $old.State -ne 'Running'){Disable-ScheduledTask -InputObject $old|Out-Null}
}
if($InstallTask -and -not(Get-Service CcmExec -ErrorAction SilentlyContinue)){
Start-ScheduledTask -InputObject $canonical
}
Copy-Item $bootstrap (Join-Path $directory 'ccmsetup.exe') -Force
& (Join-Path $directory 'ccmsetup.exe') /service /source:$source SMSSITECODE=LCI SMSMP=sgu-dc02.lci.lasalle.mx
# ccmsetup/service runs asynchronously. Its own log and CcmExec verify completion.