How to use Powershell Core on Windows? — Top Tech Notes
In this post we will see how to install powershell core on our windows machine for powershell scripting. Everything will be same. The powershell commands will be same, script writing methods will be same. It is just that we will use visual studio with powershell extension for scripting.
But before we do that we must know what powershell core is and what its benefits are.
When we say powershell core then some of you may think that it is higher version and successor of windows powershell. While that is true, it is a higher version of powershell but it is not a replacement of windows powershell. Windows powershell is going to stay with us. Its latest version 5.1 comes packaged with recent operating systems and Microsoft keeps on adding new features into it. Powershell core was developed for server core operating system and it is light weight. It runs on top of .Net core unlike windows powershell which runs on top of .Net framework. And the fact that Microsoft has made it open source paved the way for integration of powershell with linux and MacOS operating systems as well. Now powershell code is available to the developer community throughout the world. This developer community keeps on adding features and extensions for powershell making it more and more powerful. Microsoft also keeps on adding new features in powershell core extension. And so every now and then you will find new updates and features in your powershell core environment. So it has become a very powerful and robust scripting tool. Microsoft works actively on developing PowerShell Core. There are several sharp minds playing it with developing new things.
But still if you talk of windows then windows powershell has more number of cmdlets that powershell core.
There can be several things that you may not find in powershell core. On the other hand there can be several new things that you will find in powershell core. So what are the benefits of powershell core?
(1) The biggest benefit of powershell core is that it is cross platform. But still if you are windows user then you should use windows powershell because at the time of writing this section, windows powershell supports more cmdlets and modules than powershell core. For instance, for completely managing active directory with powershell you will need windows powershell active directory module.
(2)Powershell core enables developer community to help in finding and fixing bugs. While in windows powershell it is done by Microsoft alone. The fact that thousands of developer around the globe are constantly working to improve it gives a very bright prospect for powershell core in future.
(3) Powershell core enabled direct and powerful feedback from the community.
(4) And since it is officially supported on Linux platform so it has got increased credibility from Linux community as well.
Anyone can contribute to the development of powershell core. It can be me or it can be you, it can be anyone.
To be even more connected with the community, the PowerShell Team has set up regular open PowerShell Core Community Calls. In these calls, RFCs, feature requests, and bugs are discussed. The team also provides an update about the status of the project and the direction it is headed in. You can find the previously recorded community calls and an ICS file for your calendar application by navigating to the URL: https://github.com/PowerShell/PowerShell-RFC/tree/master/CommunityCall.
(5) Powershell core being platform independent also supports remoting over WSMan with basic authentication on macOS and Linux, and with NTLM-based authentication on Linux.
How to use powershell core on windows?
To use powershell core on windows we will have to first install powershell core and then we can use powershell core through visual studio code.
We can use visual studio code for scripting with windows powershell also like that we use in powershell ISE. But visual studio code is probably the best tool for PowerShell scripting. We can create PowerShell scripts with it after having the PowerShell extension installed.
Visual Studio Code is a cross-platform script editor by Microsoft and together with the PowerShell extension, it provides a rich and interactive script editing experience, making it easier to write reliable PowerShell scripts. Microsoft also recommends to use Visual Studio Code with the PowerShell extension for writing PowerShell scripts.
Powershell ISE is a built in tool while visual studio code has to be installed. There does not seem to be much development effort on powershell ISE from Microsoft. So you can safely assume VScode as the successor of powershell ISE. And it is also recommended by Microsoft to use for scripting.
Visual studio code
Visual Studio Code (VSCode) is a lightweight open-source editor, which is free for private and commercial use.
Like the PowerShell ISE, it also has IntelliSense capabilities, which are even available for many more languages. You can easily extend VSCode with the installation of additional extensions. These extensions bring code language and mark-up language capabilities.
It also comes with an integration of Git and some good debugging capabilities which provides a rich platform for software developer.
Visual studio code is fast, simple, customizable with extendable support for multiple languages. It has great IntelliSense feature with debugging and version control.
Visual studio code gives the ability to add extensions which provides customization and endless capabilities making it a very powerful tool.
So let’s stop the theoretical discussion here and let’s see how we can use powershell core and visual studio code on windows.
Powershell Core Download
On your machine navigate to the URL that you see on the screen.
It will open a Microsoft documentation page where you can see the installation instruction of powershell core.
At the time of writing the latest available version of powershell core is 7.1. So I will install powershell 7.1 on my machine.
Here on this page scroll down and in the download the installer package section click on the github release link.
It will open the GitHub page where you can see all the released version of latest powershell version.
In this section we will install powershell core on our windows machine running windows server 2016. So I will go ahead and download the 64 bit version of windows MSI package.
Powershell MSI package download will start. Wait for the download to complete.
Install PowerShell Core
Once download is completed, go to the download location and locate the setup.
Right click on it and select run as administrator.
Setup will start.
Click on next 🡪 next.
An initialization and customization window appears. Select your customization option and click on Next.
And then click on “Install”. Installation will start. In few seconds installation will complete.
Click on Finish. And you can use powershell core now. Let’s check our powershell core version.
Let’s now see how we can install visual studio with powershell extension.
To install visual studio code navigate to the URL https://code.visualstudio.com/ from your windows machine.
Here click on “Download for Windows”. This will start downloading visual studio code setup on your machine.
Once the download is complete go to the download location and run the installer.
VS Code installation wizard will start.
Accept the license agreement and click on Next.
Select the installation folder. I will go with default location. Click on Next again.
Select Start Menu folder. I will again go with default option here and click on Next.
Another wizard will open which will give you options to select any additional tasks that you would like installer to perform from the options provided. Select your desired options and click on Next again.
And then click on Install.
VS Code installation will start.
It will take just few seconds for the installation to complete.
Click on Finish and launch VS code.
So our VS code is installed and ready to use. Now to use powershell with VS code we will have to first install powershell extension.
To install powershell extension go to the Extension option on the left hand side as shown below.
Click on this Extension icon and it will show all the popular extension on the right hand side. Now in the search box above search for powershell extension. Click on the first powershell extension that you see and then click on Install to install the extension.
This will install powershell extension in VS code.
One this powershell extension is installed then a powershell explorer icon will appear in the left hand side menu bar as shown below.
Click on this powershell explorer icon and expand it. And now you can use powershell core in VS Code as well.
If you like this post, then do not forget to share this post with your friends and subscribe to our newsletter so that you can receive timely update whenever we publish any new post.
Subscribe to our newsletter!
Originally published at https://toptechnotes.com on July 4, 2022.