995 B
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) { Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..." New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 2222 } else { Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists." }
https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking
New-NetFirewallHyperVRule -Name "WslSshServer" -DisplayName "WslSshServer" -Direction Inbound -VMCreatorId '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -Protocol TCP -LocalPorts 22
Get-NetFirewallHyperVRule | Where-Object { $.Enabled -eq 'True' } | Get-NetFirewallPortFilter | Where-Object { $.LocalPort -eq 22 }