This is a one liner command script to connect to Active Directory and verify user name and password credentials provided. I am using System.DirectoryServices.DirectoryEntry .net object here to connect to LDAP server (In my case it is Active Directory). When you are connected successful with correct information you get DistinguishedName and Path information of Active directory in return.
New-Object System.DirectoryServices.DirectoryEntry('LDAP://DC=vcloud-lab,DC=com', 'domain\username', 'password')
If provided Ad credentials are not valid you will see error 'The username or password is incorrect.'
Below are the object properties information you can provide in the New-Object arguments.
string path
string path, string username, string password)
string path, string username, string password, System.DirectoryServices.AuthenticationTypes authenticationType)
System.Object adsObject
Useful Articles
Powershell one liner: Create multiple user accounts
Active Directory Powershell: Create bulk users from CSV file
Active Directory Powershell: Aduser A value for the attribute was not in the acceptable range of values
Powershell Active Directory: ADGroup Managedby - Checkbox Manager can update membership list
Powershell Active Directory: List complete hierarchy of upstream nested groups recursively of User
Powershell Active Directory: Show treeview of User or Group memberof hierarchy
Powershell Active Directory: Show treeview of nested Group members downstream hierarchy
Oneliner Microsoft Powershell Script Get members from a list of group from Active Directory in excel
Powershell Active Directory 1: Check, enable and disable child OU protect object from accidental deletion
Oneliner Powershell how to add or remove AD user members and objects in groups