← script library

Retrieve User Details from Active Directory

Active DirectoryJanuary 6, 2025

Managing user information in Active Directory is essential for ensuring effective communication and compliance. This PowerShell script allows administrators to retrieve and display detailed user information based on their usernames. This can help streamline user management tasks and ensure data accuracy. At ServerEngine, we provide powerful tools to enhance your IT management capabilities.

powershell
Import-Module ActiveDirectory

function Get-ADUserDetails {
    param (
        [string]$username
    )
    try {
        $user = Get-ADUser -Identity $username -Properties DisplayName, EmailAddress, LastLogonDate, Enabled
        Write-Host "User Details for $username:"
        Write-Host "Display Name: $($user.DisplayName)"
        Write-Host "Email Address: $($user.EmailAddress)"
        Write-Host "Last Logon Date: $($user.LastLogonDate)"
        Write-Host "Account Status: $($user.Enabled -eq $true ? Active : Disabled)"
    } catch {
        Write-Host "ERROR: User $username not found. Error: $_"
    }
}

Get-ADUserDetails -username "jdoe"

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.