0

With this code:

Get-ADUser -Filter {samaccountname -like "jsmith*"} | select samaccountname
Read-Host "what's up"

Why does my output always ask "what's up" before giving me the list of AD Users?
The issue only occurs if I use select.

DragonKing
  • 21
  • 2
  • 1
    Timing of the host interaction and success stream don't operate linearly with respect to each other in a script. Add `| Out-Host` after your `select` command to use the host for both interactions. The host won't wait for the pipeline to finish. – AdminOfThings Sep 03 '20 at 20:33
  • As I was fiddling, I also noticed that piping to Format-Table makes it wait, but I don't always want to use Format-Table. Thanks for your suggestion of Out-Host. I'll try that. – DragonKing Sep 03 '20 at 20:47
  • 1
    `Out-Host` is only an option if you're outputting to the _display_, unfortunately - see the accepted [answer to the linked question](https://stackoverflow.com/a/43691123/45375) for background information and trade-offs. – mklement0 Sep 03 '20 at 22:23

0 Answers0