I need some help in fixing the below PowerShell script to search for user samAccountName or Alias or Display Name like First Lastname in Active Directory from input typed by the user:
Code: Select all
Do {
Write-Host -Object 'Enter a samaccountname / Alias or even "First Lastname", or nothing (Press Enter) to leave; wildcards and a space separated list are not supported.'
$Input = Read-Host -Prompt 'User/List'
If ($Input) {
$(ForEach ($Username in $Input.Split(' ', [StringSplitOptions]::RemoveEmptyEntries)) {
If ($ADUser = Get-ADUser -Filter {samAccountName -like $UserName} -Properties DisplayName)
{
Write-Verbose -Message "Processing $($ADUser.DisplayName)"
"The samaccountname $($input) matching '$($UserName)'!"}
Else {
"Could not find a user with a samaccountname matching '$($UserName)'!" | Write-Warning
}
}
)}
} Until (-not $Input)
Thank you for the help so far.