Powershell Script - Easy bring up specific node webpage

Version 1

    I have created several Powershell scripts over the last several months and this is one that I have been asked about a lot recently so I thought I would share with the community. I am not an expert by any means in Powershell so if anyone has anything to add to it by all means. I welcome the feedback. Enough with the introduction and on to the script.

     

     

    If anyone out there is like me, they are starting to use Powershell more and more each day. I have grown to use it about 50% the time and what I don't know I lookup even if would take me longer than going thru a gui the first time around. Well I have been thinking wouldn't it be nice to have a script that will allow me to type in a node name in Powershell and it bring up that specific node in my browser. So that is what I have done. This saves me from opening a browser, bringing up SAM, typing in the search box, and then getting the node. I simply setup the script and then added an alias to my Powershell profile to set a keyword. So now if I type "SAM servername", it searches for the node ID in SAM, sets up the web address, brings up my browser, and pushes it thru.

     

    I need to build more logic to say node not found if it doesn't find the node, not hard I don't think, I just need to find the time. Copy and past this into a notepad and rename to .ps1. I have also attached a copy of the script. As per the usual warning use this at your own risk and I am not responsible damages done. This just does a lookup but I have to throw the legal **** out there.

     

    ####Start of script####

    # Created by Aaron Belisle

    # THS - IT Division

    # 09/01/2017 - Initial Build

     

    #####Important Info#####

    # This script was created to quickly view a node in your browser without having to go thru all the steps to bring up sam, click in the seach box, and search.

    # You must have Orion SDK installed and set-execution policy must be set to unrestricted!!

    #Before running you must setup your hashed encrypted password using the line below. This is a username that has an account within SAM.

    #GET-CREDENTIAL –Credential “domain\username” | EXPORT-CLIXML C:\Scripts\SecureCredentialsSAM.xml

    #Run this with your own creds of course. This will update the encrypted password hash in the XML if the password is changed. Makes sure the basic directory structure is there. It will create the XML if it has not been setup before

     

     

    # Load the SolarWinds Powershell snapin. Needed in order to execute the script. Requires the Orion SDK 2.0 installed on the machine this script is running from.

     

    Add-PSSnapin SwisSnapin

     

    #This is the SAM server name

     

    $ORIONSERVERNAME = 'Solawinds Server Name'

     

    # SolarWinds user name and password section. Created local account in SAM with only manage and unmanage rights. This acount is not on the SAM server just the IIS portion. This user can not access the server directly.

    # This section allows the password to be embedded in this script. Without it the script will not work. Who wants to enter a password each time.

     

    #This is using the hashed encrypted password

     

    $MyCredentials=IMPORT-CLIXML C:\Scripts\SecureCredentialsSam.xml

     

     

     

    # This is where the work begins and this gets real!!!

    param([string]$nodename)

     

     

     

    #This is connecting to SAM to pull the info we need need with info given

     

    $swis = Connect-Swis -Credential $MyCredentials -host $orionservername

     

    $nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"

     

    ##Opening the webpage

     

    (New-Object -Com Shell.Application).Open("http://$orionservername/Orion/NetPerfMon/NodeDetails.aspx?NetObject=N:$nodeid")

     

    ###END Script ####

     

     

    ##############################################################################################################

     

     

     

    Here is the alias I setup in my Powershell profile to run it with a keyword at anytime.

     

     

     

    ##Quick SAM Node Lookup##

     

    function quickview([STRING]$nodeinfo)

    {

        C:\location of script.ps1 -Nodename $Nodeinfo

    }

     

    set-item -path alias:SAM -value quickview