Matt Leyland
Matt Leyland

Reputation: 2329

Powershell - Results not combined

I have a powershell command that lists usernames and displays within a OU. When I run the following

$cs = get-aduser @ADUserParams | select-object @SelectParams
write-host $cs.DisplayName "," $cs.SAMAccountname

The results are not in the expected format:

Bob Leyland Sam Leyland , bob.leyland sam.leyland

I have tried to pass this through a loop but receive the same line twice. Out of my depth here.

I would like

Bob Leyland,bob.leyland
Sam Leyland,sam.leyland

Upvotes: 0

Views: 27

Answers (1)

arco444
arco444

Reputation: 22831

Pipe the command to ForEach-Object or % for its shorthand alias:

$cs = get-aduser @ADUserParams | select-object @SelectParams | % { write-host "$($_.DisplayName) , $($_.SAMAccountname)" }

Upvotes: 2

Related Questions