0

I'm trying to get a simple function with get-aduser to work by filtering name like **. When I run the function the first time the return is blank. When I run it a second time it returns a double value. (only one user is present in AD)
e.g.:
First run: Nothing.
Second Run:

Name     SamAccountName  EmployeeID
----     --------------  ----------
John Doe john.doe        1111111
John Doe john.doe        1111111

Here's the code:

function UserLookup {
$NameFirst = Read-Host "Please type in a First name"
$NameLast = Read-Host "Please type in a Last Name"
$NameLookup = "*$NameFirst* *$NameLast*"
$FormatEnumarationLimit = -1
Write-Host "Looking for "$NameLookup
Get-ADUser -SearchBase "DC=Emea" -Filter {name -like $NameLookup} -Properties * | Select name, SamAccountName, EmployeeID
}

function mn7{
Clear-Host
UserLookup
#Write-Host "USER:" $UserLookup
$answer = Read-Host "Press M to go to main menu, R to retry."
    while ("M","R" -notcontains $answer)
        {
            $answer = Read-Host "Press M to go to main menu, R to retry."
        }
    if ($answer -eq 'M'){Continue :menu}
    Else {mn7}
}

mn7
Loudy
  • 1
  • This is by design, PowerShell delays formatting (and therefor blocks rendering) for 300ms to wait and see if any other objects with the same formatting requirements are output. You can circumvent this behavior by tacking `| Out-Default` on to the end of the `Get-ADUser ... |Select ...` pipeline. – Mathias R. Jessen Mar 04 '22 at 12:08
  • This is it! I knew it was something awfully simple. Thanks! – Loudy Mar 04 '22 at 12:12

0 Answers0