question

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT asked YoungYang-MSFT answered

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.