"Deny this user permissions to log on to remote desktop session host server" - Powershell command

Ian Xue 37,711 Reputation points Microsoft Vendor
2020-07-16T03:00:33.537+00:00

HI Guys,

I'm looking for Powershell command to Enable/Disable the "Deny this user permissions to log on to remote desktop session host server" on user object.

Not able to find the correct attribute. can anyone please help me with poweshell command.

found some LDAP commands but i'm not sure on this. i need to set this value for bulk users.

Thanks in advance.

Regards,

Gops

https://social.technet.microsoft.com/Forums/windowsserver/en-US/6348df0d-2f3d-4c11-8ee4-768642c680b7/quotdeny-this-user-permissions-to-log-on-to-remote-desktop-session-host-serverquot-powershell?forum=winserverDS

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,561 questions
0 comments No comments
{count} votes

Accepted answer
  1. 2020-07-16T06:02:09.883+00:00

    Hi,

    Here is the script you are looking for :

    $ADUser = [ADSI]"LDAP://CN=UserName,OU=Users,DC=TestDomain,DC=com"

    $ADUser.SamAccountName #to check the account

    $ADUser.psbase.invokeSet("allowLogon",0)

    $ADUser.setinfo()

    And if you wanna have more information about this, maybe you can reference these sites:

    How to Remotely Enable and Disable (RDP) Remote Desktop?

    By default on a Windows Server Product Windows Remote Management (WinRM) is enabled, but Remote Desktop (RDP) is Disabled. On workstation operating systems neither is enabled by default, so if you want to be able to accomplish the following you will need to enable WinRM on the workstations.

    https://www.interfacett.com/blogs/how-to-remotely-enable-and-disable-rdp-remote-desktop/

    How to enable Remote Desktop using Powershell

    If you are using Windows 2012 R2 Core or if you just like using Powershell, then you may want to know how to enable Remote Desktop.

    To do this, you should go into your Core server where you should see a command box. In here, type in Powershell and press enter. This will open up the Powershell console for you to use.

    https://blog.techygeekshome.info/2014/07/how-to-enable-remote-desktop-using-powershell/

    PowerShell Problem Solver: Active Directory Remote Desktop Settings?

    During my recent PowerShell workshop in Finland, an attendee asked about Active Directory cmdlets from Microsoft in regards to remote desktop user settings. Although you can readily see the settings in Active Directory Users and Computers, Get-ADUser doesn’t retrieve them. I haven’t worked with Remote Desktop Services in quite a while, but I told him I’d look into this long-standing problem.

    https://www.petri.com/powershell-problem-solver-active-directory-remote-desktop-settings

    Really hope these can help you.

    Best wishes,

    Young Yang.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.