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

4
  • Do you need it exactly like in your question or it can be Folder: folder one instead of just folder one? Commented Oct 1, 2017 at 19:34
  • 1
    Folder: folder one will work Commented Oct 1, 2017 at 19:40
  • 3
    get-CsAdUser | Format-List DisplayName, Enabled, @{ Label = 'Folder'; Expression = { $var1 } } Commented Oct 1, 2017 at 19:41
  • OK that worked thanks Commented Oct 1, 2017 at 19:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.