How can I Automate Enabling few WinRM Services using powershell or Batfile

Anonymous
2024-05-21T13:10:17+00:00

How can I Automate Enabling below WinRM Services using Powershell or Bat file :

  1. Computer configuration -> Administrative Templates -> Windows components -> Windows remote manager (Winrm) -> winrm service (enable the following services to allow remote server management through winrm, basic auth, and unencrypted traffic)

a. Allow Remote Server Management though WinRM

b. Allow basic Authentication

c. Allow unencrypted traffic

  1. group policy -> Computer configuration -> Administrative Templates -> windows components ->windows remote shell -> allow remote shell access (enabled)

a. allow remote shell access

Windows Server Remote and virtual desktops PowerShell

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Anonymous
    2024-05-22T02:27:06+00:00

    Hi Heemansu Gehlot,

    Thank you for posting in Microsoft Support Community.

    These group policies actually set registry values, so you can set them up directly in PowerShell using the New-ItemProperty cmdlet.

    New-Item -Path HKLM:\Software\Policies\Microsoft\Windows\WinRM\Service
    # Allow basic Authentication
    
    New-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WinRM\Service -Name AllowBasic -Value 1 -Type DWord -Force
    
    # Allow Remote Server Management though WinRM 
    New-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WinRM\Service -Name AllowAutoConfig -Value 1 -Type DWord -Force
    
    # Allow unencrypted traffic
    New-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WinRM\Service -Name AllowUnencryptedTraffic -Value 1 -Type DWord -Force
    
    New-Item -Path HKLM:\Software\Policies\Microsoft\Windows\WinRM\Service\WinRS
    
    # Allow Remote Shell Access
    New-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WinRM\Service\WinRS -Name AllowRemoteShellAccess -Value 1 -Type DWord -Force
    
    0 comments No comments
  2. Anonymous
    2024-05-23T11:48:01+00:00

    I created a file named winrm_services.ps1 to execute the above-shared commands, When we run the script we get the below output for this.

    Below is the File:

    Please let me know if any suggestions.

    Thank you,

    0 comments No comments
  3. Anonymous
    2024-05-24T01:29:02+00:00

    Hi Heemansu Gehlot,

    You can run the script with the relative path ".\winrm_services.ps1" as the error message suggests. The dot "." means the current path you are using which is "C:\Users\admin\Desktop" in your screenshot. PowerShell will generate the full path of the file "C:\Users\admin\Desktop\winrm_services.ps1" automatically.

    Or you can run "C:\Users\admin\Desktop\winrm_services.ps1" directly if you want to specify the full path yourself.

    0 comments No comments