3

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)
-------       -----      ----------------------------------------------------

1 Answer 1

2

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.

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

1 Comment

The change was to minimal for me to edit but I had to modify the statement slightly. Was exactly what I was looking for. Thanks much! Select-Object SamAccountName, Name, @{E={[datetime]$d =$_.AccountExpires; ConvertTo-Date($d)};L="AccountExpires"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.