April.Fools

There are two things, that make some operations with classes/ types smooth in PowerShell. First of all we have type conversion, that will do (almost) everything that is possible to “translate” data into the type that we select. Second element that is handy at times are type accelerators, that work as aliases for types.

During PowerShell Deep Dive I found out (thank you, Kirk!) something that I was not aware of before: type accelerators are similar to aliases also when it comes to priority order: if there is type accelerator available that matches to string provided – you will get it instead of “real” type. That basically means that you can fully replace “real” type with your own implementation, all you need to do is to add type accelerator with the name of needed type and redirect it to your own type.

There are some really nice use cases of that, but today I would like to abuse it. Smile

Read more…

Advertisement