Introducing WindowsCompatibility for PowerShell Core

A major roadblock for a lot of Windows administrators in moving to PowerShell Core is the inability to use many of the popular Windows PowerShell modules they’ve become reliant on.

The WindowsCompatibility module for PowerShell Core, which saw the release of its first Release Candidate yesterday, aims to ease the transition from Windows PowerShell to PowerShell Core. It does this by using some clever black magic (okay, PSRemoting) to allow you to use your Windows PowerShell modules seamlessly from PowerShell Core!

Let’s take a closer look at this shiny new module.

1. Prerequisites

Obviously, you’ll need PowerShell Core for this. I’m using PowerShell 6.1.0, but any version from 6.0.0 and up should work. Grab a (preferably 64-bit) release from GitHub and install it, or use a script to download and install it for you. If you prefer using a tool like Chocolatey, run choco install pwsh (h/t @Jawz_84).

Alt

The WindowsCompatibility module uses remoting to work its magic, so you need to enable PSRemoting on your system. Start an elevated Windows PowerShell prompt and run

Check out the Microsoft Docs if you need more information on this.

2. Installation

Fire up PowerShell Core (I’m using PowerShell 6.1 here), and install the module by running the following:

Alt

3. Usage

The easiest way to get started with WindowsCompatibility is simply to import an existing Windows PowerShell module into your PS Core shell. Say you have the AzureADPreview module installed and would like to use it in PS Core. Simply run

and off you go!

Alt

You can now use all the cmdlets in the AzureAD module like you would in Windows PowerShell. What happens under the hood is that you’re actually remoted into a Windows PowerShell session on your own machine! This session is called the compability session. A little oddity is that the version number of the imported module is always set to 1.0, regardless of the version number of the corresponding Windows PowerShell module.

To see all the modules available for you to import, run

If you only want to see the modules that are available in Windows PowerShell but not in PS Core, run

This way you can easily see which modules you might need to import to complete a certain task.

Alt

A very nice feature of the module is being able to import modules from a different machine than localhost. Just use the -ComputerName parameter available in all the cmdlets of the module to connect to a remote machine.

If you have some code you’d like to run within the compatibility session, you can do so with

As long as the module containing the cmdlet you want to run is available in the session, you don’t even need to import the module.

Or build it out into a function which will run inside the compability session when called, using Add-WinFunction

This can come in handy when you’re using WindowsCompatibility in scripts. Note: you can only use positional parameters here, calling Invoke-HelloWorld -Name "YourName" won’t work.

Alt

And that’s about it! I think the WindowsCompatibility module is a great addition to PowerShell Core, and a must have for any Windows admin looking to start using PS Core in their daily workflows.

Since this is the release candidate I don’t expect any major change between this pre-release version and the eventual stable 1.0 version, but I’ll update this blog post as necessary if there any significant changes.

3 Comments

  1. Thanks, just watched Jeffrey Snover’s Ignite session on this today. This had me contemplating making the switch to pwsh. I have to manage a heterogeneous environment.

    Lucky to have stumbled on this on Twitter, going to try switch Monday.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.