Explain this line

Can someone explain this line to me…

@{N ="uTAD2000-DS-jobBeginDate";E ={[DateTime]::FromFileTime($PSItem."uTAD2000-DS-jobBeginDate")}}

The [DateTime] could it be replaced with something else to do a another thing? What is the N and E and why? What is the logic in “E”? Where do I find this info? I am using several websites to learn and figure out but there seems to be a missing decoder ring or something that is not making the connections for me. Any other references of anything I welcome.

@UTIISC1079 Its called calculated property and is used with Select-Object cmdlet.

Say Get-Process | Select-Object Name, here Name is the property being selected and is ideally Select-Object -Property Name.

But in some cases we might need to alter the property and PowerShell gives this wonderful feature called calculated properties. Here we use a hashtable E stands for Expression which will be a script block and N or L stands for Name or Label which will be the customised property name.

Get-Process | Select-Object -Property @{E={$_.Name.ToString().ToUpper()} ; N='Name_upper'}, Name

above code will give the normal Name and Name_upper which is the customised name in upper case, we calculate it in runtime.


Is Name and Label there because we can label any information how we want but the name is the name?

No. You can use both equally.

But … as I already mentioned in your other thread … it is recommended always to use full names of cmdlet, paramters and operators and not to use aliasses in scripts and especially not in forums like this as it makes your code easier to read. The only valid use case for those would be the console where it makes sense to save keystrokes. :wink: