Keep CED workstation Wi-Fi available before sign-in and package release 0.6.22

This commit is contained in:
alexrg committed 2026-10-14 15:48:44 -06:00
1 parent 2cca02db35
commit bfa520dec8
9 files changed
+386 -57

No files matched your search

+35 -9
View File
@@ -1,13 +1,14 @@
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName='File')]
param(
[Parameter(Mandatory)][string]$ProfilePath,
[Parameter(Mandatory,ParameterSetName='File')][string]$ProfilePath,
[Parameter(Mandatory,ParameterSetName='Xml')][xml]$ProfileDocument,
[string]$TargetOuDn = 'OU=Centro de Experiencia Digital,OU=Laboratorio,DC=lci,DC=lasalle,DC=mx',
[string]$GpoName = 'CED - Wi-Fi de salas',
[string]$DomainController = $env:COMPUTERNAME,
[string]$ReaderGroup = 'CED-WiFi-Equipos'
)
$ErrorActionPreference = 'Stop'
foreach ($file in 'Install-SguCedWifiMaintenance.ps1','Connect-SguCedWifi.ps1','Invoke-SguCedClientEnrollment.ps1') {
foreach ($file in 'Install-SguCedWifiMaintenance.ps1','Connect-SguCedWifi.ps1','Repair-SguCedWifi.ps1','Invoke-SguCedClientEnrollment.ps1') {
if (-not (Test-Path (Join-Path $PSScriptRoot $file))) { throw "Deploy the complete script set; missing $file." }
}
Import-Module ActiveDirectory
@@ -15,7 +16,7 @@ Import-Module GroupPolicy
$domain = Get-ADDomain -Server $DomainController
$ou = Get-ADOrganizationalUnit -Identity $TargetOuDn -Server $DomainController
if ($ou.DistinguishedName -notlike "*,$($domain.DistinguishedName)") { throw 'OU is outside this domain.' }
[xml]$profile = Get-Content -LiteralPath $ProfilePath -Raw
[xml]$profile = if($PSCmdlet.ParameterSetName -eq 'Xml'){$ProfileDocument.Clone()}else{Get-Content -LiteralPath $ProfilePath -Raw}
$ns = [Xml.XmlNamespaceManager]::new($profile.NameTable)
$ns.AddNamespace('w', 'http://www.microsoft.com/networking/WLAN/profile/v1')
$ssid = $profile.SelectSingleNode('//w:SSID/w:name', $ns).InnerText
@@ -33,12 +34,15 @@ if ($keyType -eq 'networkKey') {
} elseif ($keyType -ne 'passPhrase' -or $keyLength -lt 8 -or $keyLength -gt 63) { throw 'Invalid passphrase length.' }
$profile.SelectSingleNode('/w:WLANProfile/w:name', $ns).InnerText = $ssid
$profile.SelectSingleNode('//w:connectionMode', $ns).InnerText = 'auto'
$switch=$profile.SelectSingleNode('/w:WLANProfile/w:autoSwitch',$ns)
if(-not $switch){$switch=$profile.CreateElement('autoSwitch',$profile.DocumentElement.NamespaceURI);[void]$profile.DocumentElement.InsertAfter($switch,$profile.SelectSingleNode('/w:WLANProfile/w:connectionMode',$ns))}
$switch.InnerText='false'
$group = Get-ADGroup -Filter "SamAccountName -eq '$ReaderGroup'" -Server $DomainController
if (-not $group) {
$group = New-ADGroup -Name $ReaderGroup -SamAccountName $ReaderGroup -GroupCategory Security -GroupScope Global -Path $TargetOuDn -Server $DomainController -PassThru
}
if (-not $group.DistinguishedName.EndsWith(",$TargetOuDn",[StringComparison]::OrdinalIgnoreCase)) { throw 'Reader group is outside the target OU.' }
$computers = @(Get-ADComputer -SearchBase $TargetOuDn -Filter 'Enabled -eq $true' -Server $DomainController)
$computers = @(Get-ADComputer -SearchBase $TargetOuDn -Filter 'Enabled -eq $true' -Server $DomainController | Where-Object Name -match '^(AF|SD|SI)-')
$members = @(Get-ADGroupMember $group -Server $DomainController)
$add = @($computers | Where-Object { $_.DistinguishedName -notin $members.DistinguishedName })
$remove = @($members | Where-Object { $_.DistinguishedName -notin $computers.DistinguishedName })
@@ -60,7 +64,7 @@ $policyDn = "CN=CED Wi-Fi,$parent"
$escapedName = [Security.SecurityElement]::Escape($ssid)
$policyXml = '<WLANPolicy xmlns="http://www.microsoft.com/networking/WLAN/policy/v1">' +
"<name>$escapedName</name><description>Wi-Fi administrado exclusivamente para la OU CED.</description>" +
'<globalFlags><enableAutoConfig>true</enableAutoConfig><showDeniedNetwork>false</showDeniedNetwork><allowEveryoneToCreateAllUserProfiles>false</allowEveryoneToCreateAllUserProfiles></globalFlags>' +
'<globalFlags><enableAutoConfig>true</enableAutoConfig><showDeniedNetwork>false</showDeniedNetwork><allowEveryoneToCreateAllUserProfiles>true</allowEveryoneToCreateAllUserProfiles></globalFlags>' +
'<networkFilter><denyAllIBSS>true</denyAllIBSS><denyAllESS>false</denyAllESS></networkFilter>' +
'<profileList>' + $profile.DocumentElement.OuterXml + '</profileList></WLANPolicy>'
$policy = Get-ADObject -SearchBase $parent -SearchScope OneLevel -LDAPFilter '(cn=CED Wi-Fi)' -Server $DomainController -Properties ms-net-ieee-80211-GP-PolicyData
@@ -76,6 +80,7 @@ if (-not $policy) {
$entry = [DirectoryServices.DirectoryEntry]::new("LDAP://$DomainController/$policyDn")
try {
$security = $entry.ObjectSecurity
$beforeSecurity=$security.GetSecurityDescriptorSddlForm([Security.AccessControl.AccessControlSections]::Access)
$security.SetAccessRuleProtection($true, $false)
foreach ($rule in @($security.GetAccessRules($true,$false,[Security.Principal.SecurityIdentifier]))) { $security.RemoveAccessRuleSpecific($rule) }
$forestRoot = Get-ADDomain -Identity (Get-ADForest -Server $DomainController).RootDomain -Server $DomainController
@@ -88,15 +93,14 @@ try {
foreach ($computer in $computers) {
$security.AddAccessRule([DirectoryServices.ActiveDirectoryAccessRule]::new($computer.SID,[DirectoryServices.ActiveDirectoryRights]::GenericRead,[Security.AccessControl.AccessControlType]::Allow))
}
$entry.ObjectSecurity = $security
$entry.CommitChanges()
if($beforeSecurity -ne $security.GetSecurityDescriptorSddlForm([Security.AccessControl.AccessControlSections]::Access)){$entry.ObjectSecurity = $security;$entry.CommitChanges()}
} finally { $entry.Dispose() }
if ($changed) { Set-ADObject $policyDn -Server $DomainController -Replace @{'ms-net-ieee-80211-GP-PolicyData'=$policyXml} }
$adGpo = Get-ADObject $gpoDn -Server $DomainController -Properties versionNumber,gPCMachineExtensionNames
$root = Join-Path $env:WINDIR "SYSVOL\domain\Policies\{$($gpo.Id)}"
$startup = Join-Path $root 'Machine\Scripts\Startup'
New-Item $startup -ItemType Directory -Force | Out-Null
foreach ($file in 'Install-SguCedWifiMaintenance.ps1','Connect-SguCedWifi.ps1','Invoke-SguCedClientEnrollment.ps1') {
foreach ($file in 'Install-SguCedWifiMaintenance.ps1','Connect-SguCedWifi.ps1','Repair-SguCedWifi.ps1','Invoke-SguCedClientEnrollment.ps1') {
$source = Join-Path $PSScriptRoot $file
$destination = Join-Path $startup $file
if (-not (Test-Path $destination) -or (Get-FileHash $source).Hash -ne (Get-FileHash $destination).Hash) {
@@ -126,4 +130,26 @@ if ($changed) {
$link = (Get-GPInheritance -Target $TargetOuDn -Domain $domain.DNSRoot -Server $DomainController).GpoLinks | Where-Object GpoId -eq $gpo.Id
if (-not $link) { New-GPLink -Guid $gpo.Id -Target $TargetOuDn -Domain $domain.DNSRoot -Server $DomainController -LinkEnabled Yes | Out-Null }
elseif (-not $link.Enabled) { Set-GPLink -Guid $gpo.Id -Target $TargetOuDn -Domain $domain.DNSRoot -Server $DomainController -LinkEnabled Yes | Out-Null }
$filterName='CED - Wi-Fi AF SD SI'
$query="SELECT * FROM Win32_ComputerSystem WHERE DomainRole = 1 AND (Name LIKE 'AF-%' OR Name LIKE 'SD-%' OR Name LIKE 'SI-%')"
$encodedQuery="1;3;10;$($query.Length);WQL;root\CIMv2;$query;"
$filter=@(Get-ADObject -SearchBase "CN=SOM,CN=WMIPolicy,CN=System,$($domain.DistinguishedName)" -LDAPFilter '(objectClass=msWMI-Som)' -Server $DomainController -Properties msWMI-Name,msWMI-ID,msWMI-Parm2|Where-Object {$_.'msWMI-Name' -eq $filterName})
if($filter.Count -gt 1){throw 'Duplicate CED wireless WMI filters.'}
if(-not $filter.Count){
$id=([guid]::NewGuid()).ToString('B').ToUpperInvariant();$timestamp=[DateTime]::UtcNow.ToString('yyyyMMddHHmmss.ffffff-000')
$created=New-ADObject -Name $id -Type msWMI-Som -Path "CN=SOM,CN=WMIPolicy,CN=System,$($domain.DistinguishedName)" -Server $DomainController -OtherAttributes @{'msWMI-Name'=$filterName;'msWMI-ID'=$id;'msWMI-Parm1'='Wi-Fi clients AF, SD and SI only; excludes APPS and all servers.';'msWMI-Parm2'=$encodedQuery;'msWMI-Author'='La Salle';'msWMI-CreationDate'=$timestamp;'msWMI-ChangeDate'=$timestamp} -PassThru
$filter=@(Get-ADObject -Identity $created.DistinguishedName -Server $DomainController -Properties msWMI-ID,msWMI-Parm2)
}elseif($filter[0].'msWMI-Parm2' -ne $encodedQuery){throw 'CED wireless WMI query differs; inspect before modifying.'}
$reference="[$($domain.DNSRoot);$($filter[0].'msWMI-ID');0]"
$current=Get-ADObject -Identity $gpoDn -Server $DomainController -Properties gPCWQLFilter
if($current.gPCWQLFilter -ne $reference){Set-ADObject -Identity $gpoDn -Server $DomainController -Replace @{gPCWQLFilter=$reference};$changed=$true}
foreach($setting in @(
@{Key='HKLM\Software\Policies\Microsoft\Windows\System';Name='DontDisplayNetworkSelectionUI';Value=0},
@{Key='HKLM\Software\Policies\Microsoft\Windows\WcmSvc\GroupPolicy';Name='fBlockNonDomain';Value=0},
@{Key='HKLM\SYSTEM\CurrentControlSet\Services\WlanSvc';Name='Start';Value=2},
@{Key='HKLM\Software\Policies\LaSalle\CEDWifi';Name='ConfigurationVersion';Value=2}
)){
$old=Get-GPRegistryValue -Guid $gpo.Id -Server $DomainController -Key $setting.Key -ValueName $setting.Name -ErrorAction SilentlyContinue
if(-not $old -or [string]$old.Value -ne [string]$setting.Value){Set-GPRegistryValue -Guid $gpo.Id -Server $DomainController -Key $setting.Key -ValueName $setting.Name -Type DWord -Value $setting.Value|Out-Null;$changed=$true}
}
[pscustomobject]@{Gpo=$GpoName;Id=$gpo.Id;SSID=$ssid;TargetOu=$TargetOuDn;Computers=$computers.Count;ReaderGroup=$ReaderGroup;Changed=$changed}