In this section, we will cover how to install and set up PowerShell on different operating systems. PowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. It is available on Windows, macOS, and Linux.

  1. Installing PowerShell on Windows

Windows 10 and Windows Server 2016 or later

Windows 10 and Windows Server 2016 or later come with PowerShell pre-installed. However, you might want to install the latest version of PowerShell (PowerShell Core) for additional features and cross-platform capabilities.

Steps to Install PowerShell Core:

  1. Download the Installer:

  2. Run the Installer:

    • Double-click the downloaded .msi file.
    • Follow the installation wizard steps to complete the installation.
  3. Verify the Installation:

    • Open a PowerShell window (press Win + X and select "Windows PowerShell").
    • Type the following command to check the installed version:
      pwsh -v
      
    • You should see the version number of the installed PowerShell Core.

Windows 7, 8.1, and Windows Server 2008 R2, 2012 R2

For older versions of Windows, you need to install the Windows Management Framework (WMF) to get the latest version of PowerShell.

Steps to Install WMF:

  1. Download WMF:

  2. Run the Installer:

    • Double-click the downloaded .msu file.
    • Follow the installation wizard steps to complete the installation.
  3. Verify the Installation:

    • Open a PowerShell window.
    • Type the following command to check the installed version:
      $PSVersionTable.PSVersion
      
    • You should see the version number of the installed PowerShell.

  1. Installing PowerShell on macOS

PowerShell Core can be installed on macOS using Homebrew, a popular package manager for macOS.

Steps to Install PowerShell Core on macOS:

  1. Install Homebrew:

    • Open the Terminal application.
    • Install Homebrew by running the following command:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
  2. Install PowerShell:

    • Once Homebrew is installed, run the following command to install PowerShell:
      brew install --cask powershell
      
  3. Verify the Installation:

    • Open a new Terminal window.
    • Type the following command to check the installed version:
      pwsh -v
      
    • You should see the version number of the installed PowerShell Core.

  1. Installing PowerShell on Linux

PowerShell Core can be installed on various Linux distributions. Below are the steps for installing PowerShell on Ubuntu.

Steps to Install PowerShell Core on Ubuntu:

  1. Update the Package List:

    • Open a terminal window.
    • Run the following command to update the package list:
      sudo apt-get update
      
  2. Install Prerequisites:

    • Run the following command to install the required prerequisites:
      sudo apt-get install -y wget apt-transport-https software-properties-common
      
  3. Import the Microsoft GPG Key:

    • Run the following command to import the Microsoft GPG key:
      wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
      
  4. Register the Microsoft Ubuntu Repository:

    • Run the following command to register the Microsoft Ubuntu repository:
      sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/ubuntu/$(lsb_release -rs)/prod $(lsb_release -cs) main"
      
  5. Install PowerShell:

    • Run the following commands to install PowerShell:
      sudo apt-get update
      sudo apt-get install -y powershell
      
  6. Verify the Installation:

    • Open a new terminal window.
    • Type the following command to check the installed version:
      pwsh -v
      
    • You should see the version number of the installed PowerShell Core.

Conclusion

In this section, we covered how to install and set up PowerShell on Windows, macOS, and Linux. By following these steps, you should now have PowerShell installed on your system and be ready to start using it. In the next section, we will explore the PowerShell console and Integrated Scripting Environment (ISE) to help you get familiar with the PowerShell interface.

PowerShell Course

Module 1: Introduction to PowerShell

Module 2: Basic Scripting

Module 3: Working with Objects

Module 4: Advanced Scripting Techniques

Module 5: Automation and Task Scheduling

Module 6: PowerShell Remoting

Module 7: Advanced PowerShell Features

Module 8: PowerShell and DevOps

Module 9: Best Practices and Advanced Tips

© Copyright 2024. All rights reserved