Getting ready

To understand what we are talking about, here, you need to have read the following recipes:

  1. Selecting columns from the output
  2. Creating a custom object from a returned object

Let us come back to the question: Why extend type data when we can use Select-Object?

Efficiency. While you could change the name, add a calculation, and reference the calculated property with the new name, that change would have existed only in that context. If you added it to a variable,  as in the last recipe, Creating a custom object from a returned object, where we did some nifty changes to the names and also created a custom NoteProperty, that would be a long way to go about it. Enter: extension of type data.

The rule of the thumb is,  If you do something repetitively, there's an issue: you haven't considered automating it. For example,  if you run:

PS> Get-ChildItem -Path . | select Name, Length, @{Name='Age'; Expression={[math]::Round(((Get-Date) - $_.LastWriteTime).TotalDays)}}

instead of:

PS> Get-ChildItem -Path . | select Name, Length, Age

and you do it fifteen times a day, you should consider extending the object to give you what you care about.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.31.209