I started working on a PowerShell module, converting existing code examples in the SDK to “Cmdlets” Functions. The ultimate goal is to just make it easier to re-use code. My own use case in particular arose from just wanting to simplify automating primarily working with SAM & NPM nodes, but I thought this may be of interest to others, so I’m going to share it on Codeplex as well. By posting it there not only can you can get a copy of the current code, but it also allows you to submit any changes you may make back in to the main code, which will ultimately lead to more functionality, and faster ( this is just a personal project, and not a SolarWinds one, so the code is offered as-is. Plus as I'm just doing this in free-time, so it may not get updated as frequently or as often as I would ).
Why A Module?
Converting this code into a module has several benefits:
- By creating Cmdlets, actions can be performed much faster. For example, to add nodes, rather than editing a script and calling that, you can now just call something like
$swis = Connect-Swis -UserName admin -Password "" -Hostname 10.160.5.75
New-OrionNode -SwisConnection $swis -IPAddress 10.160.5.10
What this boils down to is when writing your own scripts, these can now be much smaller in size, and faster to develop, as a lot of the “plumbing” is already done (instead of having to copy and paste a 75 line script, you can now achieve the same in a couple of lines).
- It’s more intuitive, and fits conventional PowerShell Verb-Noun naming conventions. Plus, the documentation is built-in, so calling the Get-Help command can return help and examples, the same as standard Cmdlets.
- By building in error handling, and through the use of defaults and parameter sets, there is less chance for user error. For example, when building statements in either the console or the IDE it can prompt on possible options for parameters.
What functionality is available at present? At the moment it’s very much version 0.0.1, and contains a few helper Cmdlets, plus the ability to Add ICMP Nodes, Remove Nodes, and retrieve properties. Next on the to-do list is (and this is just a wishlist, so depending on time, these may or may not be completed)
- Adding in SNMP nodes
- Adding in volumes and interfaces
- Adding in WMI nodes
- Managing applications
- Setting custom properties
EDIT: Technically these are "advanced functions" and not "Cmdlets". From a users perspective they are essentially the same, the only difference being in how the code is written: Cmdlets are written in C#, advanced functions are written in PowerShell