diff options
author | mjfernez <mjf@mjfer.net> | 2025-10-16 00:35:52 -0400 |
---|---|---|
committer | mjfernez <mjf@mjfer.net> | 2025-10-16 00:35:52 -0400 |
commit | be71e00d990211292e1fb1508de2f48ab414f8a8 (patch) | |
tree | 7c63d665b0c722b7860ca2c48be91e99916c954a /AD-powershell-tools/test-ad-credentials.ps1 | |
parent | 2f463d02d70445f45a20f04787578ac937a6a4de (diff) | |
download | scripts-n-tools-be71e00d990211292e1fb1508de2f48ab414f8a8.tar.gz |
Add fixed AD scripts and discord stuff
Diffstat (limited to 'AD-powershell-tools/test-ad-credentials.ps1')
-rw-r--r-- | AD-powershell-tools/test-ad-credentials.ps1 | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/AD-powershell-tools/test-ad-credentials.ps1 b/AD-powershell-tools/test-ad-credentials.ps1 new file mode 100644 index 0000000..bd0ba84 --- /dev/null +++ b/AD-powershell-tools/test-ad-credentials.ps1 @@ -0,0 +1,47 @@ +# Adapted from: https://itpro-tips.com/test-ad-authentication-with-powershell/
+# The interesting bit about this one is that it doesn't seem to get logged by AD,
+# so you won't end up with false positives from testing creds
+
+function Test-ADAuthentication {
+ Param(
+ [Parameter(Mandatory)]
+ [string]$User,
+ [Parameter(Mandatory)]
+ $Password,
+ [Parameter(Mandatory = $false)]
+ $Server,
+ [Parameter(Mandatory = $false)]
+ [string]$Domain = $env:USERDOMAIN
+ )
+
+ Add-Type -AssemblyName System.DirectoryServices.AccountManagement
+
+ $contextType = [System.DirectoryServices.AccountManagement.ContextType]::Domain
+
+ $argumentList = New-Object -TypeName "System.Collections.ArrayList"
+ $null = $argumentList.Add($contextType)
+ $null = $argumentList.Add($Domain)
+
+ if($null -ne $Server){
+ $argumentList.Add($Server)
+ }
+
+ $principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $argumentList -ErrorAction SilentlyContinue
+
+ if ($null -eq $principalContext) {
+ Write-Warning "$Domain\$User - AD Authentication failed"
+ }
+
+ if ($principalContext.ValidateCredentials($User, $Password)) {
+ Write-Output "$Domain\$User - AD Authentication OK"
+ }
+ else {
+ Write-Warning "$Domain\$User - AD Authentication failed"
+ }
+}
+
+$csv = Import-Csv $args[0]
+ForEach ($userpass in $csv) {
+ Test-ADAuthentication -User $userpass.user -Password $userpass.password
+}
+
|