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.

2016-05-06_20-48-11


Ready to stop reading and start learning about PowerShell, DSC, Windows Server, Sharepoint, IIS and dozens of other categories? If so, check out the hundreds of free technical demo screencasts available on the new, IT career development platform TechSnips.

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: