<#
.Synopsis
   Verify AD credentials are valid 
.DESCRIPTION
   Verify AD credentials are valid ##
.EXAMPLE
   Test-ADCredential -Credential <PSCredential>
#>
function Test-ADCredential {
    [CmdletBinding()]#
    Param
    (
        [Parameter(Mandatory = $true)]
        [PSCredential]
        $Credential
    )

    Begin {
        
    }
    Process {
        If ($Credential -eq $null) {
            Write-Warning "Credentials empty"
            $status = $true
        }
        Else {
            $username = $Credential.username
            $password = $Credential.GetNetworkCredential().password
            $CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName
            Add-Type -AssemblyName System.DirectoryServices.AccountManagement
            $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
            
            #($ValidateCredential = ) | Out-Null

            If ($DS.ValidateCredentials($UserName, $Password) -eq $false) {
                $password = $null
                Write-Error "Invalid credentials or locked account."
                $status = $false
            }
            Else {
                $status = $true
            }

            $password = $null
        }
    }
    End {
    }
}