windows-firewall.ps1 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. <powershell>
  2. New-NetFirewallRule -Name "SMB445" -DisplayName "SMB445" -Protocol TCP -LocalPort 445
  3. New-NetFirewallRule -Name "WINRM5986" -DisplayName "WINRM5986" -Protocol TCP -LocalPort 5986
  4. winrm quickconfig -q
  5. winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
  6. winrm set winrm/config '@{MaxTimeoutms="1800000"}'
  7. winrm set winrm/config/service/auth '@{Basic="true"}'
  8. $SourceStoreScope = 'LocalMachine'
  9. $SourceStorename = 'Remote Desktop'
  10. $SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope
  11. $SourceStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
  12. $cert = $SourceStore.Certificates | Where-Object -FilterScript {
  13. $_.subject -like '*'
  14. }
  15. $DestStoreScope = 'LocalMachine'
  16. $DestStoreName = 'My'
  17. $DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
  18. $DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
  19. $DestStore.Add($cert)
  20. $SourceStore.Close()
  21. $DestStore.Close()
  22. winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{CertificateThumbprint=`"($cert.Thumbprint)`"`}
  23. Restart-Service winrm
  24. </powershell>