Function Get-User {
    <#
    .SYNOPSIS
        Retrieves user object information from DRA.

    .DESCRIPTION
        Queries the DRA (Directory and Resource Administrator) environment for one or
        more user objects and returns their properties. Accepts multiple user names as
        an array or via the pipeline.

    .PARAMETER UserName
        The name(s) of the user(s) to retrieve. Do not include the FQDN.

    .PARAMETER DraServer
        The FQDN of the DRA server. Defaults to "mcguire.dra.us.af.mil".

    .EXAMPLE
        Get-User -UserName 'Doe.John', 'Smith.Jane'
        Retrieves information for two users.

    .EXAMPLE
        'Doe.John', 'Smith.Jane' | Get-User -Verbose
        Retrieves information for users passed via the pipeline and shows verbose output.

    .INPUTS
        System.String
        You can pipe user names to this function.

    .OUTPUTS
        NetIQ.DRA.Admin.PowerShell.User.UserObject
        Returns a DRA user object for each user found.
    #>
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
        [string[]]$UserName,

        [Parameter(Position=1)]
        [string]$DraServer = "mcguire.dra.us.af.mil"
    )

    Begin {
        $UserName = @(Split-ToolArgumentList -Value $UserName)
        $ouPath = ",OU=McGuire AFB Users,OU=McGuire AFB,OU=AFCONUSWEST,OU=Bases,DC=AREA52,DC=AFNOAPPS,DC=USAF,DC=MIL"
        Write-Verbose "Processing users in OU Path: $ouPath"
        $i = 1
        $total = $UserName.Count
    }

    Process {
        foreach ($user in $UserName) {
            $percentComplete = ($i / $total) * 100
            Show-ProgressBar -Activity "Getting info for $user" -PercentComplete $percentComplete

            $identifier = "cn=$user$ouPath"
            Write-Verbose "Attempting to retrieve user with identifier: $identifier"

            try {
                Get-DRAUser -ErrorAction Stop `
                    -Domain $env:USERDNSDOMAIN `
                    -DRARestServer $DraServer `
                    -DRARestPort 8755 `
                    -DRAHostServer $DraServer `
                    -DRAHostPort 11192 `
                    -Identifier $identifier `
                    -Force
            }
            catch {
                Write-Warning "Could not find or retrieve user: '$user'. Error: $($_.Exception.Message)"
            }
            $i++
        }
    }

    End {
        Show-ProgressBar -Activity "Operation Complete" -PercentComplete 100
    }
}
