Skip to content

Instantly share code, notes, and snippets.

@gorvin
Created March 23, 2018 21:41
Show Gist options
  • Save gorvin/ed0b8b9738768f10e9ad7c9766ba5dcb to your computer and use it in GitHub Desktop.
Save gorvin/ed0b8b9738768f10e9ad7c9766ba5dcb to your computer and use it in GitHub Desktop.
winrm-enable.cmd
:: TODO: http://www.visualstudiogeeks.com/devops/how-to-configure-winrm-for-https-manually
powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"
C:\Windows\SysWOW64\cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"
@set TMPPS1=%temp%\setprivatenet.ps1
@echo if([environment]::OSVersion.version.Major -lt 6 -or 1,3,4,5 -contains (Get-WmiObject win32_computersystem).DomainRole) { return }> "%TMPPS1%"
@echo $networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))>> "%TMPPS1%"
@echo $networkListManager.GetNetworkConnections() ^| foreach { $_.GetNetwork().SetCategory(1) }>> "%TMPPS1%"
type "%TMPPS1%"
powershell "%TMPPS1%"
cmd /c winrm quickconfig -q
cmd /c winrm quickconfig -transport:http
cmd /c winrm set winrm/config @{MaxTimeoutms="1800000"}
cmd /c winrm set winrm/config/winrs @{MaxMemoryPerShellMB="800"}
cmd /c winrm set winrm/config/service @{AllowUnencrypted="true"}
cmd /c winrm set winrm/config/service/auth @{Basic="true"}
cmd /c winrm set winrm/config/client/auth @{Basic="true"}
cmd /c winrm set winrm/config/listener?Address=*+Transport=HTTP @{Port="5985"}
netsh advfirewall firewall add rule name="Port 5985" dir=in action=allow protocol=TCP localport=5985
net stop winrm
sc config winrm start=auto
net start winrm
:: http://divineops.net/connect-to-remote-machine-via-winrm-powershell-pssession/
@echo Please execute on client:
@echo winrm quickconfig /q
@echo winrm get winrm/config
@echo winrm set winrm/config/client @{AllowUnencrypted="true"}
@echo winrm set winrm/config/client @{TrustedHosts="*"}
@echo and use powershell command
@echo $cred = Get-Credential; Enter-PSSession 192.168.XXX.XXX -Authentication "basic" -Credential $cred
@echo for testing WinRM connection to this machine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment