Skip to content

PowerShell

PowerShell find user in Active Directory

# Import-Module ActiveDirectory
# Get-ADUser -Filter {UserPrincipalName -eq "username@domainname.com"} -Properties LockedOut, Enabled

PowerShell authenticate user in Active Directory

Import-Module ActiveDirectory
Add-Type -AssemblyName "System.DirectoryServices.AccountManagement"
$context = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Domain, "dc.office.company.com")
$context.ValidateCredentials("bindaduser@company.com", "userpassword")