1

I have a question about adding a variable to the output of format-list. When I run the command:

get-CsAdUser | Format-List DisplayName, Enabled

I get the output

DisplayName : user01
Enabled : True

DisplayName : user02
Enabled : False

I have a variable $var1 = "folder one" that I need to add to the output so it looks like :

DisplayName : user01
Enabled : True
folder one

DisplayName : user02
Enabled : False
folder one

Anyone have an idea on how to do this? Thanks

Chris Topher
  • 37
  • 2
  • 7

1 Answers1

1

On a meta note:

PetSerAl, as he often does, has provided an effective answer in a comment.

However, it is preferable to have an actual answer post that can be marked as accepted so as to signal to future readers what solution truly solved the OP's problem.


As PetSerAl notes:

get-CsAdUser | Format-List DisplayName, Enabled, @{Label = 'Folder'; Expression = {$var1}}

adds a third property to each input object's output that prints the value of variable $var1 as an ad-hoc, calculated property named Folder, following the preexisting DisplayName and Enabled properties.

The @{ Label = ...; Expression = ... } part of the command is a PowerShell hashtable literal that is an instance of a calculated property, which you can use with Select-Object, Format-Table, and Format-List, as described in this answer of mine.

mklement0
  • 382,024
  • 64
  • 607
  • 775