From this point forward the steps are identical regardless of your operating system. Your operating system may ask for permissions and there will be some visual difference on fonts or path formatting (‘/’ vs. ‘\’), but for the most part the steps are the same.
Open VS Code and choose a theme.
At this point, you can continue to explore the interface, or click Mark Done.
Click Open Folder and create a new folder in your user profile called “Scripts.” Select that new “Scripts” folder to open.
You’ll be prompted to trust the authors in the parent folder as well. Since this is in your own user profile, you can select “Trust the authors.”
Creating a Test File
In the left-hand Explorer pane, click the new file icon to create a new file in this folder.
Name that file “Test.ps1” (notice that the icon changes to match the file type).
Since this is the first “PS1” file detected for this install, VS Code prompts if you’d like to install the recommended extensions. You can either show the recommendations and install them as you wish or just take the defaults. This autodetection of file extensions works for most common file types and VS Code will suggest the required extensions for execution.
The recommendation for handling PowerShell files is just a single extension and should be installed.
Additional Recommended Extensions
On the left-hand bar, click on the ‘blocks’ to access the extensions. There are several that I like to use in addition to the required one for PowerShell, and you can either take the recommendations or leave them.
- Indent-rainbow – colorizes your tabs, making it easier to visualize script levels
- Prettier - Code formatter – formats your scripts the same way all the time
There are several thousand other extensions available. They range from those required to compile/interpret code, those for working with repositories, and those which help with the code layout/formatting itself. Choose those that work best for you and your coding style.
Installing the SolarWinds Orion PowerShell Module
In the lower half of the screen, click on the “Terminal” tab and enter Find-Module -Name SwisPowerShell
and then hit Enter.
This is the module we’ll need to install. Make sure it reports version 3.0.0 or later.
To install the module, in the same space, type Install-Module -Name SwisPowerShell
followed by Enter.
You’ll be prompted to authorize the PSGallery
as a trusted repository if you have not previously installed from it. Type Y
and hit Enter to confirm.
Lastly, we’ll need to confirm that the module’s functions are available, so type Get-Command -Name Connect-Swis
and hit Enter.
If anything is returned (as above), then that command is available from the module which is listed under Source.
Validating Our Work
We’re good to write our Test.ps1 script. Feel free to copy the below into your PS1 file or download the Test.ps1 from the GitHub repository. (link forthcoming). After you have it in your editor, be sure to change the third line to use the IP or Name of your Orion Server.
# this is the name of your SolarWinds Orion server (or IP Address) # replace with your own server name/IP $SwisHost = "kmsorion01v.kmsigma.local" #<-- replace with your server's IP or DNS name # Do we have a connection already to the SolarWinds Information Service? # If not, prompt for credentials and build one if ( -not $SwisConnection ) { $SwisCreds = Get-Credential -Message "Enter Orion credentials to connect to '$SwisHost'" $SwisConnection = Connect-Swis -Hostname $SwisHost -Credential $SwisCreds } # Simple SolarWinds Query Language (SWQL) Query $SwqlQuery = "SELECT Caption, IPAddress FROM Orion.Nodes" # Run the query against the SolarWinds Orion server Get-SwisData -SwisConnection $SwisConnection -Query $SwqlQuery
From the Menu Bar, click Run / Start Debugging, press F5, or click the “play” button in the top-right to execute the script.
In the Terminal tab you’ll be prompted for your Orion username and password.
If you get no errors and the data is returned, then you have successfully completed all the steps and are ready to build your own scripts to interact with the SolarWinds Orion API via PowerShell.