Search code examples
azurepowershellwindows-10virtual-machinerdp

Set/Edit remote desktop connection limit using powershell in windows 10


I created windows VM on azure and I login to VM using RDP. After login, I changed RDS "Limit number of connections" to 2. Now I restart the VM and I cannot login anymore. It says "The number of connections to this computer is limited and all connections are in use right now. Try connecting later or contact your system administrator"

I have access to powershell/PS and I can run any PS script in azure portal. So if any could give me PS script that will set the RDS "Limit number of connections" to x that would be great.

Note: RDS - Remote Desktop Service. You can navigate there by typing gpedit.msc to windows Run box. and then Computer Configuration -> Administrative Templates -> Windows Components -> Remote Desktop Services -> Remote Desktop Session Host -> Connections -> "Limit number of connections"

reference link https://www.top-password.com/blog/enable-multiple-remote-desktop-connections-in-windows-server/


Solution

  • There is no PowerShell script to update the group policy. To limit the number of connections, you can temporarily edit the related registry MaxInstanceCount in your Azure VM portal.

    For exmaple, add the registry MaxInstanceCount to value 300, refer here.

    New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" -Name MaxInstanceCount -Value 300 -PropertyType DWORD -Force
    

    Please note that you could update your group policy once you have login into your Azure VM because the group policy will refresh regularly. After one hour, the registry value might be changed to the original value 2.

    enter image description here