Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell -ExpandProperty and correct date format

I am attempting to use the -ExpandProperty feature in PowerShell to stop the header appearing in the output and format the date without minutes and seconds. This is just to get the created date for an AD Object:

Get-ADComputer -Server $Server -Identity BlahBlah -Properties Created |
  Select-Object -ExpandProperty @{Name="Created";Expression={$_.Created.ToString("yyyy-MM-dd")}} 

This does not produce a result, only if I exclude the "-ExpandProperty" part will it produce the right date format BUT includes the header "Created" which I don't want.

Any ideas please?

like image 287
IanB Avatar asked Oct 12 '25 05:10

IanB


1 Answers

I don't have access to an AD at the moment, but this could be what you are after

Updated

Get-ADComputer -Server $Server -Identity BlahBlah -Properties Created | Select-Object Created | ForEach-Object {$_.Created.ToString("yyyy-MM-dd")}
like image 119
Mötz Avatar answered Oct 14 '25 19:10

Mötz