PowerShell Day-to-Day Admin Tasks – Part 6: Real-Time IT Dashboard

Comments 0

Share to social media

The series so far:

  1. Automating Day-to-Day PowerShell Admin Tasks – Part 1: Jobs and Workflow
  2. PowerShell Day-to-Day Admin Tasks – Part 2: WMI, CIM and PSWA
  3. PowerShell Day-to-Day Admin Tasks – Part 3: Monitoring Performance
  4. PowerShell Day-to-Day Admin Tasks – Part 4: Securing Scripts
  5. PowerShell Day-to-Day Admin Tasks – Part 5: Events and Monitoring
  6. PowerShell Day-to-Day Admin Tasks - Part 6: Real Time IT Dashboard

Understanding your system’s performance is a crucial part of running an IT infrastructure which is why I decided to add a new article to this series. Every sysadmin should be able to monitor their environment and should send reports or dashboards to the top management on a regular basis. Of course, you can build your own dashboards using a monitoring tool, but you don’t always have a PowerShell module to automate the management of these dashboards. Otherwise, you could also use other projects, for instance, to create a dashboard based on Power BI, but some prerequisites must be validated before using it and, unfortunately, it is not straightforward for beginners.

One of the first things I always think about before using a new product is that there must be a way to control this with PowerShell. This is not a prerequisite, but it could save me a lot of time in the future. Creating a dashboard should be also done using PowerShell to dynamically create a dashboard based on some criteria. For instance, you might want to create a dashboard every morning at 07:00 AM that will list all your machines that are not up and running. Or you might want to create a dashboard that will:

  • List the top 10 machines for whom the CPU is greater than 90%,
  • List toner levels for printers
  • And anything else you can think of…

Of course, you can do this with a monitoring tool, but are you able to automate the whole creation process? Wouldn’t it be interesting to be able to launch a simple PowerShell script with several arguments and create a new dashboard on demand? In this case, every admin would be able to create a dashboard even if they don’t have PowerShell skills.

I will try to convince you without further explanation. So please run the following PowerShell commands as an administrator:

The Install-Script cmdlet acquires the script from the PowerShell Gallery, verifies that the script is a valid PowerShell script, and copies the script file to the default installation location, which is: C:\Program Files\WindowsPowerShell\Scripts.

Now, open your favorite web browser, and type the following URL: http://localhost:10000. That’s all; your first PowerShell Dashboard is up and running! Nothing more to do. Below is the output on my Windows 10 laptop:

If you launch this dashboard, you will notice that on the right side of the dashboard, the charts should auto-refresh every 5 seconds. This dashboard has been generated using PowerShell Universal Dashboard.

What is the PowerShell Universal Dashboard (PoshUD)?

PoshUD was created by Adam Driscoll and has been out since September 2017. In my opinion, it does not have many downloads despite the amazing potential of this tool. I think this module should be more popular, so I will demonstrate the ease of use of this tool and show you step-by-step how to build a real-time PowerShell dashboard for your daily tasks. PoshUD is an extremely powerful data and visualization tool. It is a cross-platform PowerShell module for developing and hosting web-based, interactive dashboards. It means that you can use your PowerShell skills to develop awesome dashboards very easily.

What about PowerShell Core? PoshUD is fully compatible with PowerShell Core, so, as you can probably imagine, it means that you can create a cross-platform dashboard and monitor Windows machines and Linux machines on the same dashboard.

Before going deeper with PoshUD, you must know that PoshUD is not free. But don’t panic because the pricing is very interesting. As of the 1.5.3 release, PoshUD is licensed per server and includes free upgrades for a year. When you will run your first dashboard, it will be unlicensed, and you will be able to run it for one hour. To run past the one hour time limit, you will be prompted to buy a license. Server licenses are available for purchase for $99.99 per server and are perpetual. If you want to use PoshUD for an open source project, contact directly Adam Driscoll to discuss the license terms.

How to Use PoshUD?

Universal Dashboard is built on ASP.NET Core, PowerShell Core, ReactJS and some JavaScript libraries but you don’t need to learn JavaScript, CSS, HTML or C#. You just have to use PowerShell to produce a dashboard. First, you can check the available commands:

Dashboards are made up of components. A dashboard is composed of one or more pages with any number of components on those pages. These components can be:

  • Charts: Charts can be bar, line, doughnut or pie.
  • Grids: Grids output data similar to tables but allow for paging and sorting the data in the grid.
  • Formatting: Layouts provide a simple way to format dashboards into columns and rows.
  • Inputs: Inputs allow you to take user input.
  • Monitors: Monitors are special charts that track data over time.
  • Pages: Dashboards can be split into multiple pages.
  • Tables: Tables are simple controls that output data in an HTML table
  • Customs: Custom Components can ship as modules or simple PS1 scripts.

Below are some component examples:

If you need help or just more information, you can use the get-help cmdlet:

Moreover, an essential concept is called Endpoints which are PowerShell Script Blocks. Endpoints properties are executed when data is requested by the client. The Endpoint parameter’s script block is called whenever a user visits the website, or the Endpoint refreshes its data. Endpoints can also call any PowerShell script to retrieve data.

Note that you can host your dashboard locally, in Azure or on your IIS server. The following code will create a very simple dashboard:

At this time, your machine is a stand-alone server and your dashboard runs on the port number that you indicate. In this case, you can access the dashboard with this URL: http://localhost:1000/

Note: You can run multiple dashboards per server as long as they listen on different ports. The dashboards are highly customizable. You can modify the dashboard to add some colors and run it once again:

Error! As I said just before, you cannot run the dashboard because it is already in use on the same port.


Start-UDDashboard : Failed to bind to address http://0.0.0.0:1000: address already in use.
At line:5 char:1
+ Start-UDDashboard -Port 1000 -Dashboard $MyDashboard
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo : NotSpecified: (:) [Start-UDDashboard], IOException 
    + FullyQualifiedErrorId : System.IO.IOException,PowerShellProTools.UniversalDashboard.Cmdlets.StartDashboardCommand 

You must stop the dashboard and run it once again. Check to see if the dashboard is still running with the Get-UDDashboard cmdlet:

You can stop the dashboard with the Stop-UDDashboard cmdlet:

After re-running the dashboard, notice the changes:

If you want to refresh your dashboard, there are two options. You can kill your dashboard and then start it again:

Or you can save your commands in a single script named myDashboard.ps1 and add the –AutoReload parameter. This will restart the server as soon as there is a change in myDashboard.ps1. Open your favorite PowerShell IDE with the page http://localhost:1000 running in the background. Simply modify your code, save your script and the running dashboard will refresh automatically

Note: The –AutoReload parameter only works in a script and does not work in command line.

Create a Functional Dashboard

Adding a monitor to your dashboard definition is simple. Use the New-UDMonitor cmdlet followed by these parameters:

  • Title: This parameter displays a title on your monitor
  • Type: This parameter allows for Bar and Line chart
  • Endpoint: This parameter contains your PowerShell command. The results are displayed on your monitor

To display your monitor, you must ‘pipe’ the New-UDMonitor to the Out-UDMonitorData cmdlet. Below is the syntax:

New-UDMonitor -Title “My Title” -Type Line -Endpoint {

Your PowerShell Command Here | Out-UDMonitorData

}

For example, if you wanted to monitor Network I/O, the Endpoint would be

Endpoint {Get-Counter ‘\Process(_Total)\IO Read Bytes/sec’ }

For more information on monitors, you can use the help:

Now, you will create a second page in your dashboard. The first one will be the home page with a form for newsletter registration, and the second one will display some monitors in real-time.

Below is the full example:

Now to examine the dashboard:

  1. The simple form will wait for an input from the user. When the user enters an email address, a toast will be created and will display the value. The toast will disappear very quickly, but you can add the –Duration parameter to increase this time.
  2. A new icon appears on the top left corner. It is called the Hamburger menu icon and will help you to switch between your pages in your dashboard.
  3. The footer will display some legal information such as a disclaimer or whatever you want.
  4. The navbar menu displays some useful links such a documentation.

You can navigate between the first page and the second page by expanding the Hamburger menu.

On the second page, you can see the monitors in real-time.

You can customize your dashboards as much as you want. It would be impossible to explain all the components in this article but note that you can create REST APIs or add a login page very easily and force https access to your dashboard. Use the New-UDLoginPage and New-UDAuthenticationMethod cmdlets:

On top of that, PoshUD is updated on a very regular basis, so do not forget to update the module to get the latest features added by Adam. To finish, note that you can check your license by running the Get-UDLicense cmdlet.

Conclusion

Keep in mind that PowerShell Universal Dashboard is a new tool, but I never noticed any bugs or strange behaviors. This module will help you to save a lot of time and easily create dashboard to monitor your infrastructure. You can create a very simple dashboard to quickly save time in your day-to-day task or create very complex dashboards if you wish. You also can run PoshUD in a Docker Container which is cool!

You can see more PowerShell Dashboard examples created by the community here. If you need more help, you can read the official documentation. There are more and more examples on internet to help you to create your dashboards.

Finally, I would like to congratulate Adam for his awesome work. This module will help many sysadmins, so please give a try to this tool, at least to test the potential of this module. I hope this article will help this tool to be more popular.

Load comments

About the author

Nicolas Prigent

See Profile

Nicolas Prigent works as a System Engineer, based in Switzerland with primary focus on Microsoft technologies. Nicolas is a Microsoft MVP in Cloud And Datacenter Management with 7 years experience in administering Windows Servers, Hyper-V and System Center products. He also received the "PowerShell Heroes 2016" Award. His blog can be found at www.get-cmd.com. You can follow him on Twitter @PrigentNico or you can contact him at simple-talk@get-cmd.com.

Nicolas Prigent's contributions