11 Replies Latest reply on May 5, 2016 11:56 AM by goodzhere

    PowerShell Module based on the SDK

    Michael Halpin

      Hi All,

       

      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.

      PowerOrionGet-Help Example.jpg

      • 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.

      PowerOrion Parameters Populated.jpg


      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)

      1. Adding in SNMP nodes
      2. Adding in volumes and interfaces
      3. Adding in WMI nodes
      4. Managing applications
      5. 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

        • Re: PowerShell Module based on the SDK
          Michael Halpin

          I updated the module (Version 0.0.3), to include some new functions, including helper functions (for things such as DNS lookups, which code be used in other scripts). Other changes include changing parameters so they are standard, as well improved error handling. -Whatif functionality added to New-OrionNode & Remove-OrionNode

           

          Here are the functions that currently exist

          • Add-OrionDiscoveredInterfaces
          • Convert-IP2OrionGuid
          • Get-HostNamefromIPAddress
          • Get-IPAddressFromHostName
          • Get-OrionNode
          • Get-OrionNodeID
          • Get-TimeStamp
          • New-OrionInterface
          • New-OrionNode
          • New-OrionPollerType
          • Remove-OrionNode
          • Test-IsValidIP

           

          Changelog viewable here

          • Re: PowerShell Module based on the SDK
            dan.cazacu

            Hi Michael,

             

            This sounds like a great idea, and I tried to install the module. I went to github and got the 3 files:

             

            Install-PowerOrion.ps1

            PowerOrion.psd1

            PowerOrion.psm1

             

            I did not modify them in any way.

             

            I put them all in a folder, and ran the Install script. Seems like it completely successfully, did not use verbose but it seems like it did copy the files. I then tried to import module using import-module PowerOrion

             

            Powershell said it can`t load the module as the manifest was either missing or corrupt.

             

            I did new-manifest in PS and gave it the path to your files, which did create a manifest.

             

            I could then load the module.

             

            However, I am trying to connect to SW using Connect-Swis -UserName admin -Password "" -Hostname 10.160.5.75

             

            At this point, this happens:

             

            OperationTimeout : 01:00:00

            Channel          :

            ClientChannel    :

            ChannelFactory   : System.ServiceModel.ChannelFactory`1[SolarWinds.InformationService.Contract2.IStreamInformationServi

                               ceChannel]

             

            Is it because this is not actually supported and it needs to be provided as a variable, and then running a command + swisconnection? Because then, it makes sense why I am getting that weird error.

             

            I am going to fiddle around with it some more since it's pretty quiet tonight and try it like in your example also, quite curios what's going to happen!

             

            Still, a PS module for SW, wow! Kudos on that!

             

            Thanks!

             

            Dan

            • Re: PowerShell Module based on the SDK
              wlipford

              Very cool - I do a similar thing but it fires off our ticketing system, basically if the device goes from operational from the ticket it then un-manages/manages the device based on that.

               

              I wonder if a version of this could be applied to a router startup, like self provisioning a discovery action to Solarwinds.....hmmm