asked on
$PWDtest = 'P@$$w0rd!'
function Test-ADCredential {
[CmdletBinding()]
Param
(
[string]$UserName,
[string]$Password
)
if (!($UserName) -or !($Password)) {
Write-Warning 'Test-ADCredential: Please specify both user name and password'
} else {
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
$DS.ValidateCredentials($UserName, $Password)
}
}
Get-User -ResultSize Unlimited | % {
If(Test-ADCredential -UserName $_.SamAccountName -Password $PWDtest){
$_ | Select SamAccountName,WindowsEmailAddress
}
} | Export-Csv C:\Results.csv