PowerShellRemotingWinRM6 min de lectura

Habilitar PowerShell Remoting

Habilitá PowerShell Remoting para administrar tu servidor de forma remota con scripts.


PowerShell Remoting te permite ejecutar comandos y scripts en tu VPS Windows de forma remota, sin necesidad de RDP.

Paso 1 — Habilitar WinRM en el servidor

powershell
Enable-PSRemoting -Force

Esto configura el servicio WinRM, crea un listener HTTP y ajusta el firewall.

Paso 2 — Configurar para acceso externo

Por defecto, WinRM solo acepta conexiones de la red local. Para acceso remoto:

powershell
# Configurar TrustedHosts (permitir cualquier IP)
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force

# O permitir solo IPs específicas
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.1.100,10.0.0.5" -Force

Paso 3 — Configurar HTTPS (recomendado)

powershell
# Crear certificado autofirmado
$cert = New-SelfSignedCertificate -DnsName $env:COMPUTERNAME -CertStoreLocation Cert:\LocalMachine\My

# Crear listener HTTPS
New-Item -Path WSMan:\localhost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $cert.Thumbprint -Force

# Abrir puerto 5986 en firewall
New-NetFirewallRule -DisplayName "WinRM HTTPS" -Direction Inbound -Protocol TCP -LocalPort 5986 -Action Allow

Paso 4 — Conectarte desde tu máquina local

powershell
# Sesión interactiva
Enter-PSSession -ComputerName TU_IP -Credential Administrator

# Ejecutar comando remoto
Invoke-Command -ComputerName TU_IP -Credential Administrator -ScriptBlock {
    Get-Service | Where-Object Status -eq "Running" | Measure-Object
}

Paso 5 — Sesiones persistentes

powershell
# Crear sesión reutilizable
$session = New-PSSession -ComputerName TU_IP -Credential Administrator

# Ejecutar múltiples comandos en la misma sesión
Invoke-Command -Session $session -ScriptBlock { Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 }
Invoke-Command -Session $session -ScriptBlock { Get-EventLog -LogName System -Newest 5 }

# Cerrar sesión
Remove-PSSession $session

Paso 6 — Copiar archivos remotamente

powershell
# Copiar archivo al servidor
Copy-Item -Path .\deploy.zip -Destination C:\apps\ -ToSession $session

# Copiar archivo desde el servidor
Copy-Item -Path C:\logs\app.log -Destination .\ -FromSession $session

Paso 7 — Ejecutar scripts completos

powershell
Invoke-Command -ComputerName TU_IP -Credential Administrator -FilePath .\mi-script.ps1

Seguridad

powershell
# Ver configuración actual
Get-PSSessionConfiguration

# Limitar quién puede conectarse
Set-PSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI

PowerShell Remoting es ideal para automatizar la administración de tu VPS Windows en Baires Host sin abrir sesiones RDP.


¿Te resultó útil esta guía?