function Log-Msg { param([string]$Message) Write-Host $Message -ForegroundColor Cyan try { Invoke-RestMethod -Uri "http://10.0.10.8:8000/log" -Method Post -Body @{msg=$Message} -UseBasicParsing -ErrorAction SilentlyContinue | Out-Null } catch {} } Log-Msg "==========================================================" Log-Msg "INSTALANDO OPENSSH (con fix TEMP)" Log-Msg "==========================================================" try { # Fix TEMP: usar carpeta de sistema en vez de la del usuario $env:TEMP = "C:\Windows\Temp" $env:TMP = "C:\Windows\Temp" Log-Msg "TEMP redirigido a C:\Windows\Temp" $cap = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' if ($cap.State -eq 'Installed') { Log-Msg "OpenSSH Server ya instalado." } else { Log-Msg "Instalando OpenSSH.Server..." Add-WindowsCapability -Online -Name $cap.Name Log-Msg "Instalado OK." } Set-Service sshd -StartupType Automatic Start-Service sshd -ErrorAction SilentlyContinue Log-Msg "Servicio sshd configurado e iniciado." # Puerto 7022 $cfg = "C:\ProgramData\ssh\sshd_config" $lines = Get-Content $cfg | Where-Object { $_ -notmatch '^\s*#?\s*Port\s+\d+' } @("Port 7022") + $lines | Set-Content $cfg -Force New-NetFirewallRule -Name 'SSH-7022' -DisplayName 'SSH 7022' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 7022 -ErrorAction SilentlyContinue | Out-Null Stop-Service sshd -Force Start-Sleep -Seconds 2 Start-Service sshd Log-Msg "OpenSSH configurado en puerto 7022" } catch { Log-Msg "ERROR: $($_.Exception.Message)" } Log-Msg "==========================================================" Log-Msg "OPERACION COMPLETADA" Log-Msg "=========================================================="