Remote connectivity in PowerShell leverages a few different technologies under the hood. For example, cmdlets that provide a -ComputerName parameter usually connect with RPC, WMI, or WinRM.
Most of the truly interesting remote capabilities come through WinRM. It allows you to enter and maintain remote console sessions, invoke remote scriptblocks, and more. One drawback is that the configuration is slightly more involved than just opening a firewall port. Fortunately we can use Group Policy to enable remoting and enforce the settings on a large scale. The group policy object (GPO) settings below do just that.
Requirements
WinRM requires PowerShell 2.0 or later. This is baked in automatically on Windows 7 or newer clients, and Windows 2008 R2 or newer servers. These instructions will not work for machines with operating systems below this requirement.
GPO Settings
Policy 1: Allow WinRM Management
- Section: Computer Configuration > Policies > Administrative Templates > Windows Components > Windows Remote Management (WinRM) > WinRM Service
- Setting: Allow Remote Server management through WinRM
- Values:
- Enabled
- IPv4 Filter: *
- IPv6 Filter: *
Policy 2: Enable WinRM Firewall Rule
- Section: Computer Configuration > Policies > Windows Settings > Security Settings > Windows Firewall with Advanced Security > Windows Firewall with Advanced Security – … > Inbound Rules
- Action: Right Click > Create New Rule
- Values:
- RuleType: Predefined: Windows Remote Management
- PredefinedRules: (leave default 2 rules)
- Action: Allow the connection
Policy 3: Ensure WinRM Service Starts
- Section: Computer Configuration > Policies > Windows Settings > Security Settings > System Services
- Service: Windows Remote Management (WS-Management)
- Action: Right Click > Properties
- Values:
- Define this policy: Checked
- Startup mode: Automatic
Policy 4: Ensure WinRM Service Restarts on Failure
- Section: Computer Configuration > Preferences > Control Panel Settings > Services
- Action: Right Click > New > Service
- Values:
- General Tab
- Startup: No change
- Service name: WinRM
- Service action: Start service
- Recovery Tab
- First failure: Restart
- Second failure: Restart
- Subsequent failures: Restart
- Restart service after: 5 minutes
- General Tab