PowerShell Universal v4.2

PowerShell Universal

November 14, 2023

quote Discuss this Article

Today, we’re happy to announce the release of PowerShell Universal v4.2! You can download directly from the PowerShell Universal downloads page. Below, you’ll find the highlights.

Computer Groups

We’ve added the ability to create groups of computers that are associated based on user name, domain or operating system. This can allow for limiting where certain APIs, scripts and apps can be run. Computer tags are automatically populated when they start up to detect their tags. This feature will supersede the current Queues feature in a future version.

New-PSUComputerGroup -Name 'Windows Machines' -Tags @("windows")
New-PSUComputerGroup -Name 'Ironman Domain Machines' -Tags @("ironman.local")

Learn more about computer groups.

Minimal Environments

Minimal environments allow for creating environments that do no load the PowerShell Universal hosting APIs or communicate via gRPC. These types of environments are only used for running scripts. Because of how these work, they can be used for environments that are not PowerShell. For example, you can setup a minimal environment that runs Python scripts. These environments are also useful for running scripts with problematic modules.

These environments collect output via STDOUT and STDERR. They do not support the following.

New-PSUEnvironment -Name 'python' -Path 'python' -Arguments '{scriptPath}' -Minimal

Learn more about minimal environments.

Plugins

As we work towards our next major release, one of our internal themes is making PowerShell Universal more extensible. Internally, we are developing a plugin API that can be used to extend the platform without directly adding functionality into the core product. In v4.2, we’ve added several new plugins that demonstrate the power of this new API but are likely not useful for all users.

C# API Endpoints

We’ve added the PowerShellUniversal.Language.CSharp plugin to allow for creating C# API endpoints. You can use .cs files with C# code that are compiled at runtime to produce APIs. C# APIs are must faster than PowerShell-based ones.

Learn more about C# APIs.

OpenTelemetry

We’ve added the PowerShellUniversal.Plugin.OpenTelemetry plugin to allow for sending telemetry data to OpenTelemetry-compatible backends. Enabling this plugin and specifying some options in appsettings.json will forward telemetry data to systems like Prometheus.

Learn more about OpenTelemetry.

YARP

YARP or (Yet Another Reverse Proxy) is a reverse proxy that can be used to route traffic from PowerShell Universal to other systems while maintaining or transforming headers, routes or other aspects of the request. The PowerShellUniversal.Plugin.YARP plugin can be configured via appsettings.json and can integrate with PowerShell Universal authorization scripts.

Learn more about YARP.

gRPC Cmdlets

We are moving from our current gRPC + REST cmdlet stack to a purely gRPC implementation. This will allow for better performance, easier implementation and less room for error. gRPC still leverages HTTP and is a first class citizen of ASP.NET Core. REST APIs are automatically generated for new functionality and will be in the /api/v2 namespace. We will use these for interactions with the admin console and you can consume them in environments that cannot load the Universal module.

Basic Authentication

We’ve added built in basic authentication to allow for easier access for users from scripts without having to generate app tokens or use web sessions.

$credentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("admin:admin"))
Invoke-RestMethod $Env:UniversalUrl/api/v1/accessible -Headers @{
    Authorization = "Basic $credentials"
} 

Learn more about basic authentication.

Custom Health Checks

You can now run custom health checks on your system alongside the built in ones. Each health check runs on each computer and then reports its status to the PowerShell Universal server.

New-PSUHealthCheck -Name 'Time Check' -ScriptBlock {
    $QuittingTime = [DateTime]'17:00:00'
    $StartingTime = [DateTime]'08:00:00'
    if ((Get-Date) -gt $QuittingTime -or (Get-Date) -lt $StartingTime)
    {
        New-PSUHealthCheckResult -Message 'Not in working hours' -Level Error
    }
    else 
    {
        New-PSUHealthCheckResult -Message 'In working hours' -Level Ok
    }
}

App Improvements

We’re constantly adding new components and parameters to our client-side framework. Some notable additions in v4.2 include:

VS Code Extension Improvements

The VS Code Extension has been updated to support new features of PowerShell Universal. The most notable feature is the ability to remotely debug scripts in your PowerShell Universal server. PowerShell Universal now includes PowerShell Editor Services. Utilizing a custom web socket implementation, the debugging features forward to VS Code. This feature will supersede the web-based debugging features in a future version.