2

I want to keep the output of this command on the same line:

((Get-ADUser -filter {employeetype -eq "Employee"}).SamAccountName) | Sort-Object | Get-ADUser | ForEach-Object {$_.Name,$_.Department,$_mail}

Currently the output shows up like this:

James Roberts
Accounting
[email protected]

But, I need to have it show up like:

James Roberts Accounting [email protected]

I've also tried using (based on a suggestion I found):

((Get-ADUser -filter {employeetype -eq "Employee"}).SamAccountName) | Sort-Object | Get-ADUser | ForEach-Object {$_.Name;$_.Department;$_mail}

but, I get the same three lines of output and not one line.

2
  • 2
    Instead of Foreach-Object you should use Select-Object -Property Commented Mar 27, 2019 at 0:54
  • to get those items on the same line, you can use -join with whatever delimiter you want. [grin] take a look at Get-Help about_Join for some useful examples. Commented Mar 27, 2019 at 1:02

1 Answer 1

1

If you want to create customized objects:

… | Select-Object -Property Name,Department,Mail

If you want to make strings:

… | ForEach-Object { $_.Name,$_.Department,$_.Mail -join " " }

If you just want to display the table nicely (not going to use this output afterwards):

… | Format-Table -Property Name,Department,Mail -AutoSize
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.