1. How to identify the current logged-on user in an Active Directory domain controller?
Imagine you are about to perform maintenance and need to shut down or demote a domain controller. Before proceeding, it is important to check if any user or administrators currently has an active session on the DC. This helps prevent unexpected disruptions, avoid interrupting ongoing tasks, and ensures maintenance can be performed safely.
To identify the users currently logged on to the domain controller, you can run the PowerShell snippet below.
$DCs = Get-ADDomainController -Identity "<DCHostName>"
foreach ($DC in $DCs) {
Write-Host "Checking sessions on: $($DC.HostName)" -ForegroundColor Cyan
if (Test-Connection -ComputerName $DC.HostName -Count 1 -Quiet) {
try {
Invoke-Command -ComputerName $DC.HostName -ScriptBlock { quser } -ErrorAction Stop
}
catch {
Write-Host "WinRM issue on $($DC.HostName): $_" -ForegroundColor Yellow
}
}
else {
Write-Host "DC not reachable: $($DC.HostName)" -ForegroundColor Red
}
}
This cmdlet uses the quser command to query active user sessions on the domain controller. It retrieves privileged users currently logged on either locally (interactive logon) or through Remote Desktop (RDP) sessions.
2. How to limit domain controller logons to specific users in Active Directory?
Domain controllers play a vital role in Active Directory by managing authentication, controlling user access, and maintaining overall domain security. If these systems are granted unrestricted logon access, it can lead to unintended configuration changes, accidental deletion of important objects, and other security issues. To prevent such risks, it is important to allow only specific users to log on to domain controllers.
This can be achieved using Group Policy Objects (GPOs), which enforce consistent security settings across the domain. The following GPO restrictions can be applied to restrict logons to only authorized users:
- Allow log on locally – Controls who can log on interactively at the domain controller.
- Access this computer from the network – Defines which users can access domain controllers.
- Log on as a batch job – Specifies which user accounts can run scheduled tasks on domain controllers.
- Log on as a service – Determines which accounts can run services on domain controllers.
- Allow log on through Remote Desktop Services – Specifies which users can connect to domain controllers via RDP.
To implement these restrictions, first create a security group containing the users who should be granted access to domain controllers. Once the group is created, follow the steps below to apply the required GPO settings.
- Open Server Manager and navigate to Tools » Group Policy Management.
- From the left console tree, right-click the Domain Controllers OU and select Create a GPO in this domain, and Link it here.
- In the New GPO dialog box, enter a descriptive name for the policy and click OK. Once created, right-click it and select Edit.
- In the Group Policy Management Editor, navigate to Computer Configuration » Policies » Windows Settings » Security Settings » Local Policies » User Rights Assignment.
- Right-click ‘Allow log on locally’ and select Properties.
- Enable Define these policy settings, and click Add User or Group.
- Type the name of the group you created, click OK, then click Apply, confirm the settings, and click OK.
- Repeat the same process for the remaining policies to enforce the required logon restrictions.
By default, the GPO applies to all domain controllers in the OU. If you want to restrict logons on specific domain controllers only, use Security Filtering in the GPO to target individual DC computer accounts.
3. How to ensure privileged users can log on only to domain controllers in Active Directory?
Let’s say you have restricted DC access to specific privileged users using Group Policy (GPO). Now, only those users can sign in and access DCs. But imagine those same users are also allowed to sign into standard workstations or other low-tier computers in your environment. When this happens, their highly privileged credentials are left exposed in the memory of those systems. If an attacker gains access to one of these low-tier systems, they can easily harvest the exposed administrative credentials and gain full control of your domain controllers.
Therefore, it is recommended to isolate these privileged accounts, ensuring that the users who can access your DCs are restricted from signing into lower-tier systems entirely.
- Open Active Directory Users and Computers console.
- Right-click the user account you want to restrict and select Properties.
- Navigate to the Account tab and click Log On To.
- Select The following computers, enter the name of the domain controllers, and select Add. Then, click OK.
- Click Apply and OK to save the changes.
The above method using the ADUC console requires you to navigate to each user account individually, which can be time consuming and inefficient when managing multiple accounts. Instead, you can use the cmdlet below to restrict a privileged user account to specific domain controllers in a single step.
Set-ADUser -Identity "<AdminUsername>" -LogonWorkstations "<DC01>,<DC02>"
Replace <AdminUserName> with the logon name of the admin account you want to restrict, and <DC01>, <DC02> with the names of the domain controllers you want to allow access to.
Tip: You can use these methods to restrict user access to any computers, including workstations and member servers.
4. What are the Windows event IDs in Active Directory to track logons on domain controllers?
Domain controllers generate different logon-related Event IDs based on the authentication and sign-in activity performed by users and systems. Understanding these Event IDs helps admins quickly identify specific logon activities without reviewing all events manually. For example, to identify users remotely accessing the domain controller, you can directly monitor Event ID 4624 with the appropriate logon type and Logon DC filter, instead of analysing every logon event. The following are the key Event IDs to monitor logons on domain controllers:
| Event ID | Message | Description |
|---|
4624 | An account was successfully logged on | Tracks successful logons to the computers by a user account |
4625 | An account failed to log on | Records failed logon attempts due to incorrect credentials or access denial |
4634 | An account was logged off | Captures the termination of a logon session on the computer |
4647 | User initiated logoff | Logged when a user manually signs out of an interactive or Remote Desktop (RDP) session |
4648 | A logon was attempted using explicit credentials | Records logons where credentials are explicitly specified, common in scheduled tasks or Run As commands |
4768 | A Kerberos authentication ticket (TGT) was requested. | Generated when a user logs on and the domain controller validates the credentials and issues a Kerberos Ticket Granting Ticket (TGT) |
4672 | Special privileges assigned to new logon | Records logons by accounts that have administrative or other sensitive privileges |
4776 | The computer attempted to validate the credentials for an account | Recorded when credential validation during a logon is performed using NTLM authentication |
4778 | A session was reconnected to a Window Station | Captures a user reconnecting to an existing Terminal Services (RDP) session, switching to an existing desktop, or reconnecting to a virtual Hyper-V host |
4779 | A session was disconnected from a Window Station | Indicates a user disconnecting from an existing Terminal Services (RDP) session, switching away from an existing desktop, or disconnecting to a virtual Hyper-V host |