• Blog
  • Webinars
  • Partner
  • Support
  • Contact
  • EN
    • DE
ScriptRunner
  • About us
    • Team
    • Jobs
    • Press
  • Why
  • Use Cases
  • Software
    • ScriptRunner Server
    • ScriptRunner Portal
    • ScriptRunner Portal Widget
    • ScriptRunner Connectors
    • ScriptRunner ActionPacks
  • Try Now
  • Search
  • Menu Menu
You are here: Home1 / ScriptRunner Blog2 / News3 / X-mas Fun with PowerShell and ScriptRunner

X-mas Fun with PowerShell and ScriptRunner

Author: Bruno Buyck | Reading time: 5 minutes | Category: News, Scripting

Christmas is the most wonderful time of year: presents, glühwein*, kissing your beloved under the mistletoe. The fancy decoration, x-mas tree, and the stunning music … don’t we all love it?
(*German for mulled wine)

Unfortunately, COVID-19 has prevented most of this. On the positive side, people get creative during lockdown, and we took the chance to demonstrate the possibilities of ScriptRunner in combination with an IOT Box.

Disclaimer: The scripts and examples are built for demo purposes and are not production ready, so proceed at your own risk!

Table of content

  • 1. Hardware requirements
  • 2. Preparing the Rest-API
  • 3. Reading the Outputs
  • 4. Setting the Outputs
  • 5. Show Time!
  • The Video
Article: X-mas Fun with PowerShell and ScriptRunner

1. Hardware requirements

For this project we used a NETIO-4C manageable PDU. The magical Blackbox has 4 x 230V outputs that can be controlled with several protocols (REST API, SNMP, MQTT, Modbus/TCP).

For our little demo we connected the following devices to the outputs and named the output in the web interface (fig. 1):

  1. Xmas Tree
  2. Disco Light
  3. Santa Claus

Output #4 was not used for our project.

Screenshot: web interface of NETIO-4C

Fig. 1: Naming the outputs in the NETIO-4C web interface

Further, we created a “write” user with a password and assigned the corresponding API permissions.

Figure 2 shows our test setup:

Photo of the test setup, showing the pdu box, a LED Christmas decoration, an LED disco-ball and an electrical Santa Claus puppet

Fig. 2: The test setup

2. Preparing the Rest-API

REST stands for REpresentational State Transfer. It is an approach to create your API’s in today’s world. API stands for Application Programming Interface and can be pictured as a waiter in the restaurant who passes the order from customer to the kitchen and delivers the result to the customer.

The main building blocks of REST-API architecture are:

  • BASE-URI
  • ENDPOINT
  • ACTION (get, post, put, merge, delete,….)

Let’s explain this with a brief PowerShell example :

In this case, the Action is GET, the Base-uri is http://api.trouble-shooter.be and the Endpoint is 007.
The result given by the API is a list of the James Bond movies with some details in a JSON format. To make it readable you can convert it from JSON to a PowerShell object with the ConvertFrom-Json commandlet (figure 3).

Screenshot: PowerShell output from running the command above

Fig. 3: List of James Bond movies retrieved with PowerShell via a REST-Api

3. Reading the Outputs

You need a bit of information to start scripting:

  • Hostname/IP of your box
  • Credentials
  • Base URI and Endpoint
Screenshot: PowerShell output from variable $io_box

Fig. 4: PowerShell output from variable $io_box

Transforming the 2 lines of code into a function and using the html formatting and shaping features of ScriptRunner (figure 5) it gives a really nice output:

Screenshot: ScriptRunner Admin App

Fig. 5: Using ScriptRunner we can turn the PowerShell output into an HTML report

The function below returns the inverse state of a specified output. The required parameters are:

  1. Credentials, by using the type System.Management.Automation.PSCredential (the built-in credential vault of ScriptRunner can be used)
  2. IP, by using the ipaddress type a built-in validation is done
  3. The output which is limited from 1 to 4 as we have 4 outputs available

4. Setting the Outputs

The following parameters are required to set the output state:

  • HostName, URI and endpoint of your box
  • Credentials
  • A body in JSON-format containing the output definition:
    • ID which represents the number of the output (1-4)
    • Action which represents the desired state (0 = Off, 4 = On)

Wrapping this piece of code into a nice function gives us the result below:

5. Show Time!

Based on this function we create an Action in the ScriptRunner Portal. For easier handling we embed it into a web page. The new ScriptRunner Portal Widget is perfect for this.

Putting the pieces of code together in ScriptRunner and combing the interface for the IOBox with the portal widget gives us a nice overview, as can be seen in figure 6 … more can be seen on the demo video.

Screenshot: Overview of NETIO outputs in the web interface next to the ScriptRunner Action that's used for controlling the test setup

Fig. 6: Using a ScriptRunner Portal Widget we can now comfortably control our test setup via PowerShell

The Video

As you can see very nicely in the video, we built our own little Christmas command center with just a few steps.
If this project has inspired you, we would of course be happy if you shared your results with us, e.g. on Twitter under the hashtag #merryscriptmas.

Happy scripting & happy holidays!

Related links

  • PowerPDU 4C | NETIO products a.s.
Share this article
  • Share on Facebook
  • Share on Twitter
  • Share on WhatsApp
  • Share on LinkedIn
  • Share on Reddit
  • Share by Mail

These articles might also be interesting for you:

Article: PowerShell PSDefaultParameterValuesScriptRunner Software GmbH

PowerShell PSDefaultParameterValues

24. March 2021
Read more
https://www.scriptrunner.com/wp-content/uploads/2021/03/Article-PSDefaultParameterValues.png 449 449 Marco Kamner https://www.scriptrunner.com/wp-content/uploads/2018/05/ScriptRunner_Logo_RGB-300x45.png Marco Kamner2021-03-24 14:10:142021-03-25 13:07:29PowerShell PSDefaultParameterValues
Artikelbild:ScriptRunner Software GmbH

5 PowerShell Scripting Best Practices – From Runnable to Professional Code

10. March 2021
Read more
https://www.scriptrunner.com/wp-content/uploads/2021/03/powershell-best-practices.png 1000 1000 Philip Lorenz https://www.scriptrunner.com/wp-content/uploads/2018/05/ScriptRunner_Logo_RGB-300x45.png Philip Lorenz2021-03-10 10:00:042021-03-10 15:22:175 PowerShell Scripting Best Practices – From Runnable to Professional Code
Article: Introducing Three Popular PowerShell Editors - Adam BertramScriptRunner Software GmbH

Software Spotlight: Introducing Three Popular PowerShell Editors

10. February 2021
Read more
https://www.scriptrunner.com/wp-content/uploads/2021/02/powershell-editors.gif 1000 1000 Adam Bertram https://www.scriptrunner.com/wp-content/uploads/2018/05/ScriptRunner_Logo_RGB-300x45.png Adam Bertram2021-02-10 10:00:112021-02-25 12:41:38Software Spotlight: Introducing Three Popular PowerShell Editors

About the author:

Bruno Buyck

Bruno Buyck is the founder of Trouble Shooter a company that specializes in PowerShell automation. The past decade Bruno delivered workshops on how to manage and automate systems with PowerShell. He has hundreds of script running in production environments which results in over 34 Million script executions every year. He loves to teach and prove that PowerShell is “What The Fuck”.

Latest posts:

  • Article: PowerShell PSDefaultParameterValuesScriptRunner Software GmbHPowerShell PSDefaultParameterValues24. March 2021 - 14:10
  • Article: ScriptRunner is sponsoring the PowerShell + DevOps Global Summit 2021ScriptRunner Software GmbHScriptRunner is sponsoring the PowerShell + DevOps Global Summit 202119. March 2021 - 10:00
  • ScriptRunner ActionPack for CitrixScriptRunner Software GmbHScriptRunner ActionPack for Citrix11. March 2021 - 13:02
  • Artikelbild:ScriptRunner Software GmbH5 PowerShell Scripting Best Practices – From Runnable to Professional Code10. March 2021 - 10:00
  • Artikelbild: Vorschau auf das Produktjahr 2021ScriptRunner Software GmbHPreview of the product year 20219. March 2021 - 10:00

Product

  • ScriptRunner Platform
  • ScriptRunner Server
  • ScriptRunner Portal
  • ScriptRunner Portal Widget
  • ScriptRunner Apps
  • ScriptRunner Connectors
  • Script Collections
  • Licensing
Get your free trial

Solutions

  • IT Administrators
  • IT Team Leaders
  • Use Cases

Resources

  • Blog
  • Documentation
  • Knowledge Base
  • Webinars
  • PowerShell Lexicon
  • PowerShell Poster
  • PowerShell Security Ebook

Company

  • About us
  • Team
  • Jobs
  • Press
  • References
  • Partner

Contact

ScriptRunner Software GmbH
Ludwig-Erhard-Straße 2
76275 Ettlingen
Germany

T: +49 7243 20715-0
M: info(at)scriptrunner.com

Request Demo
© ScriptRunner Software GmbH is a subsidiary of AppSphere AG
  • LinkedIn
  • Xing
  • Twitter
  • Facebook
  • Youtube
  • Imprint
  • Privacy Policy
  • Newsletter
Using PowerShell to Create New Citrix MCS Machines ScriptRunner Software GmbH Article: How to Establish Simple Server Monitoring via PowerShell, by Adam BertramScriptRunner Software GmbH How to Establish Simple Server Monitoring via PowerShell
Scroll to top