I was wondering why this happens, and if my 'fix' is correct:
If in the PS prompt I run two Get- commands, the first one piped into Select-Object and the second one not, no problem. But if the same two commands run in a script, first filtering with Select-Object and the second not, the first one's filter seems to be latched. For example:
Get-ADOrganizationalUnit -filter * | select-object -property name
get-aduser -Filter *
Run this as a script, and get-aduser displays only the property names, as if I'd piped the command into select-object as well.
Run them individually at the prompt, get-aduser runs as expected.
It's not just these two commands – the same happens if both commands are something like get-childitem.
IN the script, when I further piped line two: Get-ADOrganizationalUnit -filter * | select-object -property name | out-host – that seemed to fix it (or it was a 'bandaid').
Is that the correct way to handle multiple get-commands in a script, where the first one filters with select-object and a later one doesn't? And do you know why this is a problem in the script but not in the command prompt?