DEV Community

Cover image for How to Download and Install PowerShell 7 on Windows, Linux, and macOS
Adam the Automator
Adam the Automator

Posted on

How to Download and Install PowerShell 7 on Windows, Linux, and macOS

This article was written by Jeff Christman. He is a frequent contributor to the Adam the Automator (ATA) blog. If you'd like to read more from this author, check out his ATA author page. Be sure to also check out more how-to posts on cloud computing, system administration, IT, and DevOps on adamtheautomator.com!

Nowadays, sysadmins are required to know more than one operating system. That used to mean learning more than a few shell scripting languages. PowerShell Core and by downloading and installing PowerShell 7, you can change that.

It's no longer necessary to learn a new scripting language to support heterogeneous environments with PowerShell 7. PowerShell 7 is cross-platform meaning it can be installed on Windows, Linux, and other operating systems.

PowerShell 7 is supported on Windows, macOS, and Linux. It's open-source, built for heterogeneous environments and the hybrid cloud. PowerShell Core has recently become available on Windows internet of things (IoT) as well.

The cross-platform nature of PowerShell 7 means that the scripts that you write will run on any supported operating system.

PowerShell 7 vs. Windows PowerShell

The main difference between Windows PowerShell and PowerShell 7 is the platform they are built on.

Windows PowerShell is built on top of the .NET frameWork. Because of that dependency, it's only available on Windows and is launched as powershell.exe.

Note that you can run PowerShell 7 and Windows PowerShell side by side. In fact, there is no way to completely remove Windows PowerShell anyway.

PowerShell 7 is built on .NET Core and is available cross-platform and is launched as pswh.exe.

Installing PowerShell 7

This tutorial will focus on installing the latest release of PowerShell 7 at the time of this writing which is PowerShell 7.1.

There are different processes to get PowerShell 7 installed on various operating systems. Let's cover each one.

Windows

To install PowerShell 7 on Windows, navigate to the PowerShell GitHub repository and download the .msi package appropriate for your system. Then run through the wizard. Easy peasy.

Windows IoT

Windows Iot devices already have PowerShell installed which we will use for installing Powershell Core


#Enter a psession to the device
$s = New-PSSession -ComputerName <deviceIp> -Credential Administrator

#Copy the file to the device
Copy-Item .\PowerShell-7.1.0-win-x64.msi -Destination u:\users\administrator\Downloads -ToSession $s

#Connect to the device and expand the archive
Enter-PSSession $s
Set-Location u:\users\administrator\downloads
Expand-Archive .\PowerShell-7.1.0-win-x64.zip

#Setup Remoting
Set-Location .\PowerShell-7.1.0-win-x64

# Be sure to use the -PowerShellHome parameter otherwise it'll try to create a new endpoint with Windows PowerShell 5.1
.\Install-PowerShellRemoting.ps1 -PowerShellHome .

# You'll get an error message and will be disconnected from the device because it has to restart WinRM
# Connect to the device. Be sure to use the -Configuration parameter. If you omit it, you will connect to Windows PowerShell 5.1
Enter-PSSession -ComputerName <deviceIp> -Credential Administrator -Configuration powershell.7.1.0

Once in the session, you should then be running PowerShell on the IoT device!

Ubuntu, Debian

For Linux distributions, it just a matter of adding the repository and installing with the package manager.


# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

CentOS and RedHat


# Register the Microsoft RedHat repository
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

# Install PowerShell
sudo yum install -y powershell

# Start PowerShell
pwsh

OpenSUSE

# Register the Microsoft signature key
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

# Add the Microsoft Repository
zypper ar https://packages.microsoft.com/rhel/7/prod/

# Update the list of products
sudo zypper update

# Download and Install PowerShell 7
sudo zypper install powershell

# Start PowerShell
pwsh

Fedora

# Register the Microsoft signature key
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

# Register the Microsoft RedHat repository
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

# Update the list of products
sudo dnf update

# Install a system component
sudo dnf install compat-openssl10

# Download and Install PowerShell 7
sudo dnf install -y powershell

# Start PowerShell
pwsh

MacOS

For macOS, Homebrew is the preferred package manager. Installing Homebrew package manager is a single line command from a terminal, then install Powershell Core.


/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

#install PowerShell Core
brew cask install powershell

#start session
pwsh

Summary

Learn to manage different platforms and OSs. It'll only help your career. When you need a cross-platform scripting language, try out PowerShell Core to write once and deploy everywhere. It's another tool in your toolbox.

If you don't learn it, someone else will.

Top comments (1)

Collapse
 
jackalbruit profile image
Jackson Brumbaugh

Thanks for clarifying the distinction b/t WinOS PowerShell & PowerShell 7!
{=