PowerShell Core 6.0.2 – new features explained

You’ve probably already heard the news that PowerShell Core 6.0 was General Available GA since January  10th this year. Although this version is in the wild for about 6 months now, still a lot of use have no idea what it is, and how to use it.

Let me try and explain the differences and improvements made to this new generation of PowerShell.

The big name change

In 2006 Microsoft introduced Windows PowerShell as a configuration management framework for Windows admins to provide them with a powerful set of command line tools. Since that the language has improved dramatically and many new features has been added.

If you have payed attention the noticeable “hidden” change is that the name of the product has changed from Windows PowerShell to just PowerShell. Main reason for this name change is that the product is not only related to just Windows anymore.

One of the reasons for this name change is that when Windows PowerShell was introduced in 2006 it was a Microsoft Windows command line tool to run tasks and automation jobs on Windows environments. Now days Windows PowerShell can be used to manage a large variety of systems from local operating systems to hyper scale cloud environments.

To be able to use PowerShell Core on all platforms, Microsoft decided to use .NET Core, a scaled down open source version of the .NET Framework for Windows and Linux, as foundation for this product.

Many other os distributors like Linux, Ubunto and Apple had their own management tools like bash, python and puppet.

PowerShell Core is not meant to replace all those great tools, but is a tool for DevOps to Manage Windows, Azure, Hyper-V, Linux and Mac OsX without the necessity to switch between Windows and other platforms to manage them all.

How to get started with PowerShell Core

The easiest way to get started and install PowerShell Core 6.0.2 is by using chocolatey. Chocolatey is a Windows package manager to easily install Windows software from any command line.

PowerShell Core can be found here:
https://chocolatey.org/packages/powershell-core/6.0.2

What I like most about this chocolatey is that will also downloads all prerequisites like Windows KB’s, etc. needed to install the software. It can also be used to keep software up-to-date.

To install the latest version of PowerShell Core with chocolatey use the following command:

choco install powershell-core --pre -y

 

More information can be found on https://chocolatey.org

choco-install-pscore-small

To run PowerShell Core you need to start pwsh.exe instead of PowerShell.exe The executable can be found in folder C:\Program Files\Powershell\6-preview\ Although the language hasn’t changed, some of the cmdlets  like login in to Azure are different. More about that later.

To see what version is running the following variable can be checked. This will show an overview the release that’s running.

$PSVersionTable

If you wan’t to be able to use PowerShell Core with Microsoft Azure, there are still some modules that needs to be installed. These module names differ from the previous Windows version because, as explained before, the framework has changed to .NET Core So when installing these modules the correct version needs to be selected.

Install-Module AzureRM.NetCore -AllowPrerelease -Force
Import-module AzureRM.NetCore
Import-Module AzureRM.Profile.Netcore

 

I’ve added the switches -AllowPrerelease and -Force to get the latest and greatest version of the modules.

After importing the modules you can check if all modules are as expected. During the writing of the post the latest version of the Modules is 0.12.0 This can easily checked by running the next command:

get-Module -ListAvailable

blog-netcore-modules-small

New commands and features

With the new .NET Core Framework 2.0 Microsoft added some nice features to PowerShell Core. Also a new method has been implemented to connect to the Azure Environment from your running instance

With the current June 2018 release, all Windows PowerShell modules are updated to the .NET Core version. This is great because now you can use all PowerShell functions that were available in the PowerShell Core!

Connecting to Azure

In the “old” days, which isn’t to long ago we used the cmdlet Login-AzureRmAccount to login to the Azure Environment. This method is no longer available in PowerShell Core and has been replaced with the cmdlet:

Connect-AzureRmAccount

After executing this cmdlet a message is shown in the console telling you that you have to login your device using the provided login code. I’m not fully convinced that this is handy, because this makes it less usable to automate things which was one of the main reasons of using PowerShell. Maybe this is still something in development, or I haven’t found out yet.

blog-pscore-login-small

If you wait to long without entering the generated device login code, the following error will be shown that your verification has expired. Connect-AzureRmAccount : AADSTS70019  : Verification code expired.

New Features!

Yes, we finally came to the part that discusses some of the new and improved features of PowerShell Core. Lets start with intellisense.

Tab Completion and intellisense
We all know the tab completion function from PowerShell to select the correct parameter, but you always had to hit the TAB button multiple times. And if you finally found the required parameter, you still had to look for the right value.

In PowerShell Core you can now use the CTRL+SPACE bar to show the possible options that the parameters allows in shown in a sort of ‘dropdown’ menu where you can select your value from. A great example is when your creating a VM and don’t know if the region is written as ‘west europe’ or ‘westeurope’

Depending on the location where you subscription resides, the new intellisense will show the values that you expect. So if your tenant is running in Germany or in the Azure US Government Cloud, other values will show up.

Also when selecting the parameter -ImageName and hitting the CTRL+SPACE a list of possible Image Types will be shown.

This is Awesome!

PowerShell Smart Defaults
Smart defaults is another great piece of art from the Microsoft Team. When creating for example a Virtual Machine, you always had to provision all the specific parameters for the dependencies the VM has, like size, virtual network name, resource group, etc.

Now with smart defaults the VM and it’s depended resources will be created based on the name property.

New-AzureRmVM -Name "Azurekid-VM" -ImageName UbuntoLTS

Resources that will be created based in this name are: Resource Group, Virtual Machine, Network Interface, Public IP, vNet, Subnet and a Network Security Group

Great way to quickly deploy a sandbox environment or testing machine. 

As-Job
Creating job’s in PowerShell was for me always a frustrating thing to do. Although it can be great to start multiple jobs at the same time, I preferred just building my own script for parallelism. Now with the new As-Job parameter things got a lot easier.

Still this will result in waiting for the deployment is finished before the interface is available again. When doing deployments as jobs, they will be run in the background and in the meanwhile you can continue doing other tasks.

Checkout this video showing some of the new features!

blog-pscore-functions-small

Please feel free to leave a comment or share this post!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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