Start-Transcript -Path C:\setup.log -Append $ErrorActionPreference = 'Continue' if (-not (Get-Service sshd -ErrorAction SilentlyContinue)) { Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 } Set-Service -Name sshd -StartupType Automatic Start-Service sshd $keys = 'C:\ProgramData\ssh\administrators_authorized_keys' Get-Content (Join-Path $PSScriptRoot 'vm_key.pub') | Set-Content -Path $keys -Encoding ascii icacls $keys /inheritance:r /grant 'Administrators:F' /grant 'SYSTEM:F' New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -PropertyType String -Force ` -Value 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' if (Get-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -ErrorAction SilentlyContinue) { # the built-in rule only covers the Private profile; QEMU user networking is Public Set-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -Profile Any -Enabled True } else { New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' ` -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Profile Any } powercfg /change monitor-timeout-ac 0 powercfg /change standby-timeout-ac 0 New-Item -Path C:\setup.done -ItemType File -Force Stop-Transcript