PowerShell Schulung in Hannover
Strukturierte Lernpfade für IT-Administratoren & Entwickler – vom Einstieg bis zur Cloud-Automatisierung.
Wenn Sie mit Powershell überprüfen möchten, ob eine gegebene Kombination aus einem AD-Benutzernamen und Kennwort korrekt ist (z.B. aus einer GUI-Eingabe), hilft Ihnen die .NET-Assembly System.Directore.Accountmanagement weiter (mind. .NET-Framwork 3.5). Die Klasse "PrincipalContext" enthält eine Methode ValidateCredentials, die die Überprüfung übernimmt. Die Funktion check_AdUserPassword liefert True oder False zurück und kann z.B. direkt in einem IF-Statement weiter genutzt werden.
Function Test-AdUserPassword
{
param (
[string]
$UserName,
[string]
$Password,
[string]
$UserDomain)
# Lädt die Assembly "System.DirectoryServices.AccountManagement" in Powershell
$Null = Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ContextType = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$PrincipalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ContextType, $UserDomain)
$PrincipalContext.ValidateCredentials($UserName,$Password)
}
Strukturierte Lernpfade für IT-Administratoren & Entwickler – vom Einstieg bis zur Cloud-Automatisierung.
Offene Kurse, Aufbautrainings, Graph-API & Active-Directory-Automatisierung in Hannover oder Online.
When you subscribe to the blog, we will send you an e‑mail when there are new updates on the site so you wouldn't miss them.
Comments