Does Powershell have an "eval" equivalent? Is there a better way to see a list of properties and values? Does Powershell have an "eval" equivalent? Is there a better way to see a list of properties and values? powershell powershell

Does Powershell have an "eval" equivalent? Is there a better way to see a list of properties and values?


To get the value of properties of an object, you can use several methods.

First off, you could use Select-Object and use the -Property parameter to specify which property values you would like returned. The how that is displayed will depend on the number of properties you specify and the type of object that it is. If you want all the properties, you can use the wildcard ( * ) to get them all.

Example -

$myobject | Select-Object -Property name, length$myobject | Select-Object -Property *

You can also control the formatting of the outputs in a similar manner, using Format-List or Format-Table.

Example -

$myobject | Format-List -Property *$myobject | Format-Table -Property name, length

Finally, to do an "eval" style output you could simply type

$myobject."$propertyname" 

and the value of the property will be returned.


For you purpose the best choice is Format-Custom.

get-date | Format-Custom -Depth 1 -Property * get-childitem . | select-object -first 1 | Format-Custom -Depth 1 -Property *

It's maybe too verbose, but useful ;)


Or you can really use Get-Member

$obj = get-date$obj |    gm -MemberType *property |    % { write-host ('{0,-12} = {1}' -f $_.Name, $obj.($_.Name)) }


For this I would recommend using Format-List -force e.g.:

Get-Process | Format-List * -Force

-Force is optional but sometimes PowerShell hides properties I really want to see.