Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to authenticate an user in ActiveDirectory with powershell

I would like to authenticate an user in my ActiveDirectory with the Username and the Password. Is there any chance to do that with powershell and the activeDirectory module. Thank you

like image 858
andreaspfr Avatar asked Oct 05 '11 14:10

andreaspfr


People also ask

How does PowerShell connect to Active Directory?

Connecting to the AD driveType Import-Module ActiveDirectory in the PowerShell window and press Enter. Now we need to set the working location to the AD drive. Type Set-Location AD: and press Enter. Notice that the PowerShell prompt now changes to PS AD: >.

How do I check Active Directory credentials?

To test a username and password against the Active Directory, run the ad auth command in the Policy Manager CLI. This command manually checks against Active Directory to indicate whether or not a username and password are valid. –u indicates the username. –n indicates the NetBIOS domain name.

Does Active Directory do authentication and authorization?

An Active Directory domain controller authenticates and authorizes users in a Windows-domain network by enforcing security policies for all computers.


1 Answers

There are multiple ways of doing this. Here is a quick and simple function which authenticates a user to AD.

Function Test-ADAuthentication {
    param($username,$password)
    (new-object directoryservices.directoryentry "",$username,$password).psbase.name -ne $null
}

PS C:\> Test-ADAuthentication "dom\myusername" "mypassword"
True
PS C:\> 

It might not be the best function for your needs but your question lacks details.

like image 112
CosmosKey Avatar answered Oct 20 '22 07:10

CosmosKey