Enable SSH in Windows 10 with PS

this script automates the process of setting up an OpenSSH server on a Windows machine, ensuring it’s ready to accept SSH connections.

# run the code as administrator
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
    Write-Host "This script needs to be run as Administrator!" -ForegroundColor Red
    exit
}

# Install OpenSSH Server feature
Write-Host "Installing OpenSSH Server..." -ForegroundColor Yellow
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Write-Host "Starting OpenSSH Server..." -ForegroundColor Yellow
Start-Service -Name sshd

Write-Host "Configuring OpenSSH Server to start on boot..." -ForegroundColor Yellow
Set-Service -Name sshd -StartupType 'Automatic'

# Allow SSH through the firewall
Write-Host "Allowing SSH through Windows Firewall..." -ForegroundColor Yellow
New-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -DisplayName "OpenSSH Server (SSH-In)" -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

Write-Host "Made By ClumsyLulz" -ForegroundColor Green

Write-Host "OpenSSH Server installation and configuration complete!" -ForegroundColor Green

Note: the code is not mine but helps me so much i hope this help u too :grinning:

3 Likes