Windows OS Hub
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux

 Windows OS Hub / PowerShell / Validating AD User Credentials with PowerShell

March 24, 2026

Validating AD User Credentials with PowerShell

In PowerShell scripts that prompt for a username and password, you sometimes have to validate the entered user credentials before performing any actions. If the user has entered an incorrect login/password, you must determine this and prompt them again.

To test the credentials of the AD user account against the current Active Directory domain, use the following PowerShell function:

$creds=Get-Credential
Function Test-ADCreds {
param($username, $password)
(New-Object DirectoryServices.DirectoryEntry "",$username,$password).psbase.name -ne $null
}
Test-ADCreds -username $creds.UserName -password $creds.GetNetworkCredential().password

Test AD authentication (credentials) from PowerShell script

Enter the domain username and password (use one of the following formats: username, domain\username, or username@domain.name ). The script will return True if the user credentials provided are valid.

PowerShell: Check if an AD account's password is valid

If the script returns False, the possible causes are

  • Invalid username (check that the account exists on a domain) or password
  • The user’s account is disabled or locked in the AD
  • The domain is not available.
The Active Directory PowerShell module (part of RSAT tools) isn’t used in this PowerShell script. This means that it can be used to validate a user’s credentials from any Windows computer.

To connect to a domain controller from a computer in a workgroup or another domain, specify an LDAP connection string. Change line 4 of the script as follows:

(New-Object System.DirectoryServices.DirectoryEntry 'LDAP://DC=woshub,DC=loc', $username, $password).psbase.name -ne $null

Or connect to the domain controller using its IP address:

(New-Object System.DirectoryServices.DirectoryEntry 'LDAP://192.168.100.10', $username, $password).psbase.name -ne $null

If the user is added to the Protected Users domain security group, be sure to specify the username with the domain name in the samAccountName (woshub\username) or userPrincipalName (username@woshub.loc) format. In this case, Kerberos authentication is used instead of NTLM.
0 comment
2
Facebook Twitter Google + Pinterest
PowerShellQuestions and Answers
previous post
Run PowerShell Scripts on a Schedule with Task Scheduler
next post
Check the Software Installation/Removal History in Windows

Related Reading

Extend an Expired User Password in Active Directory

December 23, 2024

How to Assign (Passthrough) a Physical GPU to...

June 11, 2024

Tracking Printer Usage with Windows Event Viewer Logs

March 12, 2024

How to Add or Remove Pinned Folders to...

August 11, 2024

Adding ESXi Host to VMware vCenter Server (vCSA)

March 12, 2024

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

March 17, 2024

How to Hide (Block) a Specific Windows Update

March 3, 2025

Check the Software Installation/Removal History in Windows

October 8, 2024

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • We Can’t Sign In to Your Account: Fix Temporary User Profile in Windows

    October 20, 2026
  • Backup/Sync to Cloud Storage with Rclone on Windows

    October 9, 2026
  • Fix Missing “Yes” Button in User Account Control Prompt on Windows

    October 7, 2026
  • Block Specific Keyboard Shortcuts with Keyboard Filter on Windows

    October 3, 2026
  • How to Set Task Priority in Windows Task Scheduler

    September 22, 2026
  • AutoStart Program at RDP Logon in Windows RDS

    September 8, 2026
  • How to Convert Windows Machine into a Proxmox VM

    August 30, 2026
  • Enable or Disable Fast User Switching in Windows 11

    August 18, 2026
  • How to Hide Wi-Fi Network in Windows with WLAN Filters (Blacklist and Whitelist)

    August 14, 2026
  • Invalid Signature Detected: Check Secure Boot Policy [Fix]

    August 5, 2026

Follow us

  • Facebook
  • Twitter
  • Youtube
  • Telegram
Popular Posts
  • How to Hide (Block) a Specific Windows Update
  • Run Elevated Commands with Sudo on Windows 11
  • Fix: Slow Startup of PowerShell Console and Scripts
  • Automate Software and Settings Deployment with WinGet Configure (DSC)
  • Backup/Sync to Cloud Storage with Rclone on Windows
  • Pin and Unpin Apps to Taskbar in Windows 11 via PowerShell
  • How to Pause (Delay) Update Installation on Windows 11 and 10
Footer Logo

@2014 - 2026 - Windows OS Hub. All about operating systems for sysadmins


Back To Top