I have a Cmdlet Get-AdUser that I am piping to a select object and in that select running a function on the AccountExpires property to convert the Property Value to a date value.
My question is when the object is output the column heading is no longer friendly and inherits the function used to return the new value. How do I form the statement so a friendly name is output? Was hoping to not have to assemble my own PSObject.
Get-AdUser "some.account" -Properties AccountExpires | select Enabled, Name, $({[datetime]$d =$_.AccountExpires; ConvertTo-Date($d)})
I then get a resulting table header of...
Enabled True [datetime]$d =$_.AccountExpires; ConvertTo-Date($d)
------- ----- ----------------------------------------------------
Use an expression hashtable of @{E={scriptblock};L="Label"}.
select Enabled, Name, @{E={$({[datetime]$d =$_.AccountExpires; ConvertTo-Date($d)})};L="AccountExpires"}
See http://technet.microsoft.com/en-us/library/ee692794.aspx for more information on creating custom selected objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With