I was recently lurking in Slack and saw that Kirk Munro had posted a tip that I had previously done only with C#. Kirk showed us how to define custom object types by using the [pscustomobject] type accelerator by simply defining a PSTypeName property.

By using PSTypeName as a property and the type as the value like below, we can create custom objects with a specific type.


Don't just learn from my blog and keep that newfound knowledge to yourself! Share it! I've created a new service called TechSnips that's dedicated to helping technology professionals share their knowledge and look awesome in the process! Through small screencast videos, full courses and written content, TechSnips is a community to help you grow your career. Join us!.

You can now see that the object isn’t just a PSCustomobject  but shows up as the type we just defined. This is also useful when passing these kinds of objects into functions as well.

I can now build a function like this which will only accept the PSType  I just declared.

Pretty cool!

%d bloggers like this: