Export-Csv a variable from ForEach-Object

I have a list of user IDs that I want to verify exist in AD. If I just view the output it works well but if I use Export-Csv I get some weird text like:

TYPE System.String



# This works

Get-Content .list.txt | ForEach-Object { if (dsquery user -samid $_){$_} } 

# This doesn’t work

Get-Content .list.txt | ForEach-Object { if (dsquery user -samid $_){$_ | Export-Csv -Append -Path $Output} } 

What do I need to do to get the output into a text file?

submitted by /u/edwincastle
[link] [comments]

Leave a Reply