Enabling Powershell Remoting using Win-RM
- In enterprise setups we have domain controlled and it is easier to configure the windows remoting.
- In this session, since we are trying to communicate over public networks, we would be making some tweaks
- Create a Windows Server (2016). Launch Powershell as an admin\
Set-ExecutionPolicy RemoteSigned
Winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="512"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
- Lets try to connect to winrm from Powershell on Client
$credential = Get-Credential qtdevops
Enter-PSSession -ComputerName <> -Credential $credential
- The above command leads to error as we are communicated over public networks, if you try the same command b/w client & server connected in the same domain, you will not see this issue.
- To resolve this. Enter gpedit.msc in the run command
- Now Navigate to Local Computer Policy => Computer Configuration => Administrative Templates => Windows Components => Windows Remote Management (winrm) => WinRM Client
- Enable Allow Basic Authentication & Allow unecrypted Traffic
- Now open Trusted Hosts and add the computer name of the server to trusted hosts
- Now Execute Enter-PSSession Cmdlet
- Now since the powershell terminal is connected to the other remote server, administration & execution of commands can be done from Powershell Terminal.
Powershell Scripts
- For the first powershell script Refer Here
- Ensure your Execution Policy is not Restricted
Get-ExecutionPolicy
- Install IIS Server: Refer Here
Next Steps:
- We need to refine our scripting capabilities
- Create functions
- Accept Parameters
- Should be able do some administrative tasks.
- Active Directory