Combreal

deployOpenSSHServer.ps1

Dec 8th, 2020
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requierement might be to set the following settings via GPO :
  2. #Never attempt to download payload from Windows Update => Disabled
  3. #Download repair content and optional features directly from Windows Update instead of Windows Server Update Services (WSUS) => Enabled
  4.  
  5. If ((Get-WindowsOptionalFeature -Online -FeatureName NetFX3).State -eq "Enabled")
  6. {
  7.     #Install OpenSSH
  8.     Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  9.    
  10.     #Start and configure the service
  11.     Start-Service sshd
  12.     Set-Service -Name sshd -StartupType 'Automatic'
  13.     New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
  14. }
  15. Else
  16. {
  17.     #Install FrameWork 3.5
  18.     Dism /online /enable-feature /featurename:NetFX3 /All /Source:\\share\stuff\FrameWork-3.5\dotnetfx35.exe
  19.     $RunOnceKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
  20.     $ScriptPath = $MyInvocation.MyCommand.Definition
  21.     $ScriptExecPath = "C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -File "
  22.     $ScriptFullExecPath = $ScriptExecPath + $ScriptPath
  23.     Set-ItemProperty $RunOnceKey "NextRun" $ScriptFullExecPath
  24.     Restart-Computer
  25. }
  26.  
  27. #To connect via a SSH client : ssh AD\username@servername
Add Comment
Please, Sign In to add comment