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 is changing that.
It's no longer necessary to learn a new scripting language to support heterogeneous environments with PowerShell Core. PowerShell Core is cross-platform meaning it can be installed on Windows, Linux and other operating systems.
PowerShell Core 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 Core means that scripts that you write will run on any supported operating system.
PowerShell Core vs. Windows PowerShell
The main difference between Windows PowerShell and PowerShell Core 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.
PowerShell Core is built on .NET Core and is available cross platform and is launched as pswh.exe.
Installing PowerShell Core
There are different processes to get PowerShell Core installed on various operating systems. Let's cover each one.
To install PowerShell Core on Windows, navigate to the GitHub repository and download the .msi package appropriate for your system. Then run through the wizard. Easy peasy.
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-6.1.0-win-arm32.zip -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-6.1.0-win-arm32.zip #Setup Remoting� Set-Location .\PowerShell-6.1.0-win-arm32 # 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.6.1.0
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
# 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 # Install PowerShell sudo zypper install powershell # Start PowerShell pwsh
# 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 # Install PowerShell sudo dnf install -y powershell # Start PowerShell pwsh
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
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.
Subscribe to Adam the Automator
Get the latest posts delivered right to your inbox