In this recipe, you'll learn how to provision PowerShell Core on a Windows system starting with Windows 6.1 (Server 2008 R2/Windows 7).
Installing PowerShell Core on Windows
Getting ready
To follow this recipe, you'll need a Windows machine with at least Windows Server 2008 R2 or Windows 7. If this machine isn't connected to the internet, you'll need a way of transferring the installer to the machine.
How to do it...
Please perform the following steps:
- In order to get the most recent release of PowerShell Core for Windows, browse to https://github.com/powershell/powershell:
- Download the release for your platform. I recommend using the stable 64 bit (x64) edition if possible.
- Open the installer file, for example, PowerShell-6.2.0-win-x64.msi.
- Follow the instructions on screen to install PowerShell Core
- On the final page, you can directly enable PowerShell remoting if you want. Leave the option disabled for now; you'll configure it properly later on:
- Start PowerShell Core by typing pwsh into the search bar!
How it works...
Using the standard MSI installer methods, PowerShell Core will be installed for your system in the 64 bit Program Files directory by default. It won't replace Windows PowerShell but will simply coexist peacefully and include the most recent updates to PowerShell.
If left on the default settings, an event manifest will be registered on the system, enabling an event log for PowerShell Core. The log file will be placed at %SystemRoot%\System32\Winevt\Logs\PowerShellCore%4Operational.evtx and can be found in the Applications and Services Logs.
By default, no remoting configuration will be made. We'll talk about remoting in Chapter 8, Running Remote Commands and Understanding Just Enough Administration, where you'll enable PowerShell remoting for a system.
There's more...
Besides the installer that you can download and install manually or through any software deployment solution, you can also use Chocolatey. Chocolatey is a NuGet package source for binary packages and can be used to bootstrap software on a system.
The following steps will install Chocolatey and PowerShell Core on a Windows system. These steps require using Windows PowerShell for the initial process:
- Run the following command in Windows PowerShell (see https://chocolatey.org/docs/installation for details):
Set-ExecutionPolicy Bypass -Scope Process -Force
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
- After the installation of Chocolatey, simply execute choco install powershell /y.
- Start PowerShell Core by searching for pwsh in the search bar!
If you're so inclined, compiling the code from scratch is of course also an option. Simply follow the guidelines laid out in the GitHub repository to do so:
# Clone the repository
git clone https://github.com/powershell/powershell
Set-Location -Path .\powershell
Import-Module ./build.psm1
# Ensure you have the latest version of .NET Core and other necessary components
Start-PSBootStrap
# Start the build process
Start-PSBuild
# Either run PowerShell directly...
& $(Get-PSOutput)
# ...or copy it to your favorite location (here: Program Files on Windows, necessary access rights required)
$source = Split-Path -Path $(Get-PSOutput) -Parent
$target = "$env:ProgramFiles\PowerShell\$(Get-PSVersion)"
Copy-Item -Path $source -Recurse -Destination $target
See also
- PowerShell documentation: https://docs.microsoft.com/powershell
- Chocolatey documentation: https://chocolatey.org/docs/installation