Hey all!
I am in the middle of making my first public PowerShell module. It is a wrapper for a SaaS product’s RESTful API. Any way – the API is a basic CRUD API that works on a couple dozen or so object types (user, region, customer, et cetera). With a couple exceptions (for user-defined fields), these are all well defined as far as what fields are contained for these objects.
My module essentially lets you run functions such as Get-<object name>
with parameters, which really just runs a simple GET query to the vendor’s API endpoint for whatever the object is (so, Get-Regions
for example). I’m working on the functionality to support New-
(which would map to the Create functionality), Set-
(which maps to Update), and Remove-
(which maps to Delete).
I assume that, given that the objects are for the most part fairly well defined – best practice be to create custom object types that are shared across all of the functions dealing with a specific entity? The only thing I fear is that one of the API endpoints supports custom entities that I couldn’t pre-package into the module. What is the best practice for dealing with these (dynamic?) objects?
I found this awesome StackOverflow post regarding custom object declarations in varying versions of PowerShell. Given that I am creating a module for public use, would the best practice to be to go the older (PowerShell v2) way of using Add-Type
, or would it make sense to just require PowerShell 3+ and use a PSCustomObject
? I would fear that using the PS 5 class
and enum
would be a big limiting factor on backwards compatibility.
Lastly – I’ve been searching around, but are there any blog posts, books, or articles any of you would recommend regarding using custom objects in modules? Making this module has been a huge learning experience for me, and I’m trying to learn and adhere to the best practices wherever I can.
Thanks!
submitted by /u/IHappenToBeARobot
[link] [comments]
The post Best Practices for Custom Objects in a Module appeared first on How to Code .NET.