Powershell – add a Column ,Field, Property to an object

Simple thing that I keep forgetting, how do I add a property (column) to a object in powershell

$result = Get-DHCPServerv4OptionValue -ComputerName 2012-dhcp1 -ScopeID 10.104.0.0 |select *,@{label=”DHCPServer”; Expression= {“2012-dhcp1”}}

#
$result = Get-DHCPServerv4OptionValue -ComputerName 2012-dhcp1 -ScopeID 10.104.0.0 |select *,@{label=”DHCPServer”; Expression= {"2012-dhcp1"}}
#

the key is the pipe of whatever object you are creating  to a select * command, then followed by the “column” expression (the column you want to add)   Here is a link to a simple example, I needed to get the list of options per scope to compare one DHCP server scope to another. I use out-gridview a lot as I can copy and paste the results to excel or any app really. Also I can drag and drop the columns and change selection criteria, to filter the results.

Link

One thought on “Powershell – add a Column ,Field, Property to an object

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.