Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Active Directory / How to Allow or Deny Workstation Logons for AD Users

June 8, 2023 Active DirectoryGroup PoliciesPowerShellWindows Server 2019

How to Allow or Deny Workstation Logons for AD Users

By default, when you create new Active Directory users, they are automatically added to the Domain Users group. In its turn, the Domain Users group is added to the local Users group on a domain workstation when it is joined to the AD domain. This means that any domain user can log on to any computer in the domain. In this article, we’ll look at how to allow or dey user logon to the domain computers.

Contents:
  • Allow a User to Logon Only to Specific AD Computers
  • How to Set the User LogonWorkstations Attribute with PowerShell?
  • Configuring Logon Hours for Active Directory Users
  • How to Deny or Allow Workstation Logons with Group Policy?

Allow a User to Logon Only to Specific AD Computers

You can specify a list of computers that a user is allowed to logon locally in the properties (attributes) of an Active Directory user account. For example, you want to allow a specific user to log in only on their own computers. To do it:

  1. Open the ADUC snap-in (Active Directory Users and Computers) by running the dsa.msc command;
  2. Use AD search to find the user account you want to restrict and open its properties;
  3. Go to the Account tab and click on the “Log On To” button; ad user account properties
  4. As you can see, the user is allowed to log on to all domain computers (The user can log on to: All computers). To allow a user to authenticate only on specific computers, select The following computers option and add the names of the computers a user can log on to;ad user property - logon workstations option
    Note. You must specify the full NetBIOS or DNS computer name (you cannot use wildcards). The value is not case-sensitive.
  5. You can add up to 64 computers to this list. If you try to add a 65th computer, the following error message appears: This property is limited to 64 values. You must remove some of the existing values before you can add new ones; LogonWorkstations This property is limited to 64 values
  6. Save the changes. Now the user is allowed to logon only to the specified computers.
You can use the Active Directory Administrative Center snap-in (dsac.msc) or PowerShell to add more than 65 computer devices to this list. However, the maximum value is limited by the data type of the Logon-Workstation attribute in the Active Directory schema (Octet String). In Windows Server 2016+, this attribute can contain up to 8192 characters (previous versions of Windows Server 2003-2012 used a limit of 1024 characters).

Another interesting issue occurs if you restrict the user’s list of computers allowed to log on using the LogonWorkstation attribute. When you try to connect to a remote computer (or RDS farm) via RDP, you may get an error:

The system administrator has limited the computers you can log on with.

To solve this problem, you need to add the computer name from which (!!!) the RDP login is performed to the LogonWorkstation list.

How to Set the User LogonWorkstations Attribute with PowerShell?

It is rather tedious to manually add devices to the list of computers allowed to login in each user’s properties (wildcard is not supported). You can automate this task with PowerShell. The list of computers a user is allowed to logon is stored in the AD user attribute “LogonWorkstations”. For example, our task is to allow a specific user to log on only to the computers, which names are listed in the text file computers.csv (in this example, the first line of the file should contain the column name – NetBIOSName).

The script can look like this:

Import-Module ActiveDirectory
$ADusername = ‘asmith’
$complist = Import-Csv -Path "C:\PS\computers.csv" | ForEach-Object {$_.NetBIOSName}
$comparray = $complist -join ","
Set-ADUser -Identity $ADusername -LogonWorkstations $comparray
Clear-Variable comparray

powershell script to restrict ad logonworkstations

The Set-ADUser cmdlet is used to change the attributes of an Active Directory user.

Using the Get-ADUser cmdlet, you can display a list of computers a user is allowed to log on to.

Get-ADUser $ADusername -Properties LogonWorkstations | Format-List Name, LogonWorkstations

Or, you can view the list of computers in the ADUC console.

active directory logon workstations restriction

To add a new computername to the list, use this command:

$Wks = (Get-ADUser asmith-Properties LogonWorkstations).LogonWorkstations
$Wks += ",man-b2-wks2"
Set-ADUser asmith -LogonWorkstations $Wks

Configuring Logon Hours for Active Directory Users

You can restrict the login time of the user in the user account properties. For example, you can allow a user to log on to domain computers only during business hours from 8:00 am to 7:00 pm.

  1. Open the user properties in the ADUC snap-in, go to the Account tab and click the Logon Hours button;ad user logonhours attribute
  2. By default, user logon hours are not restricted (everything is highlighted in blue);
  3. Highlight the time ranges where you want to prevent user from logging in and click the Logon Denied button (the color of the logon hours where users are not allowed to sign in will change to white).active directory restrict permittedlogonhours in user properties

If you need to apply the same Logon Hours restrictions to multiple users, the easiest way is to use PowerShell. First, manually configure restrictions for one user, and then use the value of its LogonHours attribute as a template for other users. For example, you want to restrict the logon hours for a group of VPN users:

$template_user='k.muller'
$template_hours= Get-ADUser -Identity $template_user -properties logonHours
Get-ADGroupmember "mun-VPNUsers" |foreach {Set-ADUSer $_.samaccountname -Replace @{logonHours = $template_hours.logonHours} }

If a user tries to logon to the computer outside the allowed hours, they will receive an error:

Account restrictions are preventing this user from signing in. For example: blank passwords aren't allowed, sign-in times are limited, or a policy restriction has been enforced.

windows 10: Account restrictions are preventing this user from signing in

There is no built-in functionality in Windows to force a user to logout when the logon hours expired. You can create a simple scheduler task and deploy it through a GPO to run a logoff command.

Also note the two GPO options under Computer configurations -> Policies -> Windows Settings -> Security Settings -> Local Policies -> Security Options.

  • Network security: Force logoff when logon hours expire
  • Microsoft network server: Disconnect clients when logon hours expire

Group Policy: Force logoff when logon hours expire

When these Group Policy settings are enabled, SMB servers will disconnect users whose working hours have expired.

How to Deny or Allow Workstation Logons with Group Policy?

In large domains, using the LogonWorkstations user attribute to restrict user access to computers is inconvenient because of limitations and lack of flexibility. You can use Group Policy to implement a more flexible way to allow or deny local logins.

You can restrict the list of users in the local Users group using the Restricted Groups policy (see the example of using Restricted Groups options from the Windows Settings -> Security Settings GPO section to add users to the local Administrators group). But we’ll consider another option.

There are two Group Policy options located in the GPO section Computer Configuration -> Policies -> Security Settings -> Local Policies -> User Rights Assignment:

  • Deny log on locally – allows to disable local logon to computers for specific users or groups;
  • Allow log on locally – contains a list of users that are allowed to log on to a computer locally.

For example, to prevent users of a security group from logging on to computers in the specific Active Directory Organizational Unit (OU), you can create a separate user group, add it to the Deny log on locally policy, and link the GPO to the OU containing the computers you want to restrict logon to.

Deny log on locally policy

gpo to deny local logon workstation

In large Active Directory domains, you can use a combination of these policies. For example, you want to prevent users from logging on to computers in other OUs.  To do it, create a security group in each OU, and add all OU users to it.

Tip. You can automatically add users of a specific OU to your security group using the Get-ADUser and Add-ADGroupMember PowerShell cmdlets. Use the following PowerShell script:

Import-module ActiveDirectory
$rootOU = “OU=Users,OU=UK,DC=corp,DC=woshub,DC=com”
$group = “corp\lon-users”
Get-ADUser -SearchBase $rootOu -Filter * | ForEach-Object {Add-ADGroupMember -Identity $group -Members $_ }

Then enable the “Allow log on locally” Group Policy option, add this group to it (as well as different administrator groups: Domain Admins, workstation admins, etc.), and link the policy to the OU with the computers. Thus, you will allow only the specific OU users to log on to the computers.

If a user from different OU (who is not allowed to log on locally) tries to log on the computer, a window with the following message will appear:

Update the Group Policy settings on the client computers. If a user is not allowed to logon locally, an error message will appear:

You cannot log on because the logon method you are using is not allowed on this computer.  Please see your network administrator for more information.

Or:

The sign-in method you are trying to use isn’t allowed. For more info, contact your network administrator.

The sign-in method you are trying to use isn’t allowed. For more info, contact your network administrator

Here are some important notes regarding logon restriction policies:

  • Don’t apply these policies to restrict access to the servers or AD domain controllers;
    How to allow non-admin users to access domain controllers over RDP.
  • Don’t enable these Group Policies through built-in GPOs: Default Domain Policy or Default Domain Controllers Policy;
  • A deny policy takes precedence;
  • Don’t forget about service accounts (including gMSA), that can be used to run services on computers (servers);
  • Don’t apply GPOs that restrict local logon to the entire domain. Link them only to the specific OUs;
  • Users will be able to connect to computers using interactive RDP sessions even if the deny local logon policy is enabled. To do this, the RDP protocol must be enabled on the computer, and the user account must be a member of the Remote Desktop Users group.

 

3 comments
4
Facebook Twitter Google + Pinterest
previous post
Get a List of Mailboxes a User Has Access to in Exchange/Microsoft 365
next post
Network Computers are not Showing Up in Windows 10/11

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

November 7, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

3 comments

Dilan Velasquez October 7, 2022 - 2:28 pm

Good day,

It is that I have a problem when implementing Log On To in the company where I am working, since when I choose and configure the user so that he only enters a certain computer that is in the domain, he loses the connection with the other applications that are on the servers, it is necessary add the servers in the Log On To so that the users can manage the applications?

Reply
admin October 16, 2022 - 6:10 am

Are your applications on remote servers published via RDS/RemoteApp?

Reply
Clr36 November 1, 2023 - 5:16 pm

Thanks, Never used this feature before. Your post made my day easier.

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configure Google Chrome Settings with Group Policy
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • Allow Non-admin Users RDP Access to Windows Server
  • How to Find the Source of Account Lockouts in Active Directory
  • How to Disable or Enable USB Drives in Windows using Group Policy
  • Get-ADComputer: Find Computer Properties in Active Directory with PowerShell
  • Configuring Proxy Settings on Windows Using Group Policy Preferences
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top