Retrieve User Details from Active Directory

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. Check out our software at [ServerEngine](https://serverengine.co) for more solutions tailored to your needs.
### Step 1: Import the Active Directory Module
Before executing the script, ensure that the Active Directory module is available in your PowerShell session. This module grants access to necessary cmdlets for managing Active Directory.
“`powershell

Import-Module ActiveDirectory

### Step 2: Define the Function to Retrieve User Details
We will create a function named `Get-ADUserDetails` that retrieves detailed information about specified Active Directory users.
“`powershell

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: $_"
    }
}

### Step 3: Execute the Function
To retrieve user details, execute the function by providing the username of the user you wish to inquire about.
“`powershell

Get-ADUserDetails -username "jdoe"

### Conclusion
This PowerShell script provides an efficient way to retrieve and display essential information about users in Active Directory, making user management easier and more streamlined. For more effective IT management tools, explore what [ServerEngine](https://serverengine.co) has to offer.