Programming + ScriptingPowershell Active Directory - Get Users  Updated October 22 2025
Get the list of all users and show all details:
Copy to Clipboard Get-ADUser -Filter '*' -Properties mail | sort SamAccountName | fl *



Get the list of all users which are enabled:
Copy to Clipboard Get-ADUser -Filter 'enabled -eq $true' -Properties mail | Select-Object -Property samaccountname | sort samaccountname



Get the list of all users which are disabled:
Copy to Clipboard Get-ADUser -Filter 'enabled -eq $false' -Properties mail | Select-Object -Property samaccountname | sort samaccountname



Get the list of users and show the last login time noted:
The formatting of this code is not very good, it came from an online website. I plan to simplify it later on.
Copy to Clipboard Import-Module ActiveDirectory function Get-LastLogonEvents { $dcs = Get-ADDomainController -Filter {Name -like "*"} $users = Get-ADUser -Filter * $time = 0 foreach($user in $users) { foreach($dc in $dcs) { $hostname = $dc.HostName $currentUser = Get-ADUser $user.SamAccountName | Get-ADObject -Server $hostname -Properties lastLogon if($currentUser.LastLogon -gt $time) { $time = $currentUser.LastLogon } $dt = [DateTime]::FromFileTime($time) Write-Host $dt " was the last login for " $currentUser.Name $time = 0 } } } Get-LastLogonEvents
Search Keywords: time, enabled, disabled




©2024 - Some portions of this website are Copyrighted.
Your IP: 216.73.216.36     Referring URL:
Browser: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Terms and Conditions, Privacy Policy, and Security Policy