Table of Contents
For the last ~10 years , Microsoft released Windows PowerShell. On January 10th, 2018, Microsoft delivered PowerShell Core 6.0. Its first PowerShell Core release.
PowerShell now comes in two flavors, Windows PowerShell and PowerShell Core. Windows PowerShell is the edition of PowerShell built on top of .NET Framework (known as FullCLR). As a result, it can only be installed on Windows Client and on Windows Server. However, PowerShell Core is a new version of PowerShell built on top of .NET Core (known as CoreCLR). PowerShell Core is cross platform, and available for install on Windows, MacOS and various distributions of Linux.
It is important to note that while there are two versions today, PowerShell Core is the future of PowerShell as announced by the PowerShell Team here, with the exception that only bug fixes will be added to the stable version of Windows PowerShell going forward.
The good news is, PowerShell Core can run completely side-by-side with Windows PowerShell. In fact, an awesome feature of PowerShell Core is that you can test new versions without affecting existing workloads. So the exiting installation of Windows PowerShell is not affected by PowerShell Core.
With the GA release of PowerShell Core, Microsoft ship only the following set of “built-in” PowerShell modules:
Aside from the cross-platform compatibility between Windows PowerShell and PowerShell Core, the PowerShell Core Shell and desktop icon are black color.
Since I believe in Hyper-V! I need to use all the PowerShell Cmdlets that comes with Hyper-V on PowerShell Core instead of Windows PowerShell. I feel at this point that we should get on board with PowerShell Core, the earlier the better.
In this post, I will show you how to run Hyper-V PowerShell Cmdlets on PowerShell Core.
Install PowerShell Core
First things first, we need install PowerShell Core on Windows. To install PowerShell on a Windows client or Windows Server (supported on Windows 7 SP1, Server 2008 R2, and later), you need to download the MSI package from the following repository. Since we are only interested in Windows Server 2016, we will install PowerShell-6.0.0-win-x64.msi package.
Copy the MSI package to your Windows Server 2016 Hyper-V and launch the setup wizard. The installation is straightforward.
When the setup is completed. Select Launch PowerShell and click Finish.
You can also launch PowerShell Core by typing pwsh.exe from the Command Prompt on Windows.
The first PowerShell command that I used to run on Windows PowerShell is Get-VM.
Sorry, ‘Get-VM‘ is not recognized as the name of a Cmdlet, function, script file, or operable program.
If you recall, beginning in Windows PowerShell 3.0 and later, modules are imported automatically when any cmdlet or function in the module is used in a command. This feature works on any module in a directory that this included in the value of the PSModulePath environment variable. If you do not save your module on a valid path however, you can still load them using the explicit Import-Module option.
But since we have only the following modules starting with PowerShell Core V6.0. Hyper-V Cmdlets won’t run by default.
As mentioned by the PowerShell Team in their announcement, many modules that ship as part of a Microsoft product such as Hyper-V, Storage, etc. are designed for Windows PowerShell and highly compatible with PowerShell Core. However, unless a module is explicitly supported in PowerShell Core by Windows or by the Product Group, there is no guarantee that it will work with PowerShell Core.
Add Hyper-V Module for usage in PowerShell Core
The goal of PowerShell Core is to remain as compatible as possible with Windows PowerShell.
Microsoft made the effort to ensure that the PowerShell language and “built-in” modules work the same as they do in Windows PowerShell. In some cases, due to a missing dependency in underlying .NET layers, functionality was removed or is unavailable.
Most of the modules that ship as part of Windows (i.e., DnsClient, Hyper-V, NetTCPIP, Storage, etc.) and other Microsoft products including Azure and Office have not been explicitly ported to .NET Core yet. As of this writing, the PowerShell team is working with these product groups and teams to validate and port their existing modules to PowerShell Core.
By installing the WindowsPSModulePath module from PowerShell Gallery, you can use Windows PowerShell modules by appending the Windows PowerShell PSModulePath to your PowerShell Core PSModulePath.
First, you need to install the WindowsPSModulePath module by running the following command in PowerShell Core:
Install-Module WindowsPSModulePath -Force
After installing WindowsPSModulePath module, run the Add-WindowsPSModulePath cmdlet to add the Windows PowerShell PSModulePath to PowerShell Core:
If you always want to use Windows PowerShell PSModulePath in PowerShell Core, then you need to add Add-WindowsPSModulePath cmdlet in your profile.
The install directory for PowerShell Core is C:\Program Files\PowerShell and the user directory is C:\users\<username>\documents\PowerShell. This is where you’ll store your profile.ps1 and any user specific Modules/Scripts.
Once you add Add-WindowsPSModulePath into your profile. You will have access to all modules that are available in Windows PowerShell PSModulePath.
Now all Hyper-V PowerShell Cmdlets will run in PowerShell Core V6.0 :)
Thanks for reading!
I hope you enjoy PowerShell Core 6.0 with Hyper-V as much as I do.