- 1 year ago
How to persist Enable-PSRemoting in powershell
To persist the Enable-PSRemoting
configuration in PowerShell, you need to ensure that the necessary settings are applied across PowerShell sessions and system restarts. Here's how you can do it:
Open an elevated PowerShell window (Run as Administrator).
Run the
Enable-PSRemoting
command to enable PowerShell remoting:
powershellEnable-PSRemoting -Force
- Configure the firewall to allow remote PowerShell connections. This step is essential to allow incoming remote connections to your machine:
powershellEnable-NetFirewallRule -Name "WINRM-HTTP-In-TCP-NoScope"
- Start the WinRM service to enable remote connections:
powershellStart-Service WinRM
- To make these changes persistent, you can create a Group Policy Object (GPO) on a domain-joined machine, or create a scheduled task on a standalone machine that runs at startup to execute the necessary PowerShell commands.
For example, to create a scheduled task that runs at startup, follow these steps:
Open Task Scheduler (search for "Task Scheduler" in the Start menu).
In the Actions pane on the right, click "Create Basic Task."
Follow the wizard to set the task name and description.
For the trigger, select "When the computer starts."
For the action, choose "Start a program."
In the "Program/script" field, enter
powershell.exe
.In the "Add arguments (optional)" field, enter the PowerShell script to enable remoting and configure the firewall:
powershellEnable-PSRemoting -Force
Enable-NetFirewallRule -Name "WINRM-HTTP-In-TCP-NoScope"
Start-Service WinRM
- Complete the wizard to create the scheduled task.
Now, each time your computer starts, the scheduled task will run, enabling and configuring PowerShell remoting.
Remember that enabling PSRemoting opens up potential security risks, so make sure to understand the implications and use it judiciously.