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.
- 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:
-
Download the Installer:
- Go to the PowerShell GitHub releases page.
- Download the latest
.msi
package for Windows.
-
Run the Installer:
- Double-click the downloaded
.msi
file. - Follow the installation wizard steps to complete the installation.
- Double-click the downloaded
-
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.
- Open a PowerShell window (press
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:
-
Download WMF:
- Go to the Microsoft Download Center.
- Download the appropriate WMF installer for your version of Windows.
-
Run the Installer:
- Double-click the downloaded
.msu
file. - Follow the installation wizard steps to complete the installation.
- Double-click the downloaded
-
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.
- 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:
-
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)"
-
Install PowerShell:
- Once Homebrew is installed, run the following command to install PowerShell:
brew install --cask powershell
- Once Homebrew is installed, run the following command to install PowerShell:
-
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.
- 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:
-
Update the Package List:
- Open a terminal window.
- Run the following command to update the package list:
sudo apt-get update
-
Install Prerequisites:
- Run the following command to install the required prerequisites:
sudo apt-get install -y wget apt-transport-https software-properties-common
- Run the following command to install the required prerequisites:
-
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 -
- Run the following command to import the Microsoft GPG key:
-
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"
- Run the following command to register the Microsoft Ubuntu repository:
-
Install PowerShell:
- Run the following commands to install PowerShell:
sudo apt-get update sudo apt-get install -y powershell
- Run the following commands to install PowerShell:
-
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
- What is PowerShell?
- Installing and Setting Up PowerShell
- PowerShell Console and ISE
- Basic Commands and Syntax
- Help System in PowerShell
Module 2: Basic Scripting
- Variables and Data Types
- Operators in PowerShell
- Conditional Statements
- Loops in PowerShell
- Functions and Scripts
Module 3: Working with Objects
- Understanding Objects
- Object Properties and Methods
- Pipelines and Object Manipulation
- Filtering and Selecting Objects
- Sorting and Grouping Objects
Module 4: Advanced Scripting Techniques
- Error Handling
- Debugging Scripts
- Regular Expressions
- Working with Files and Directories
- Using Modules and Snap-ins
Module 5: Automation and Task Scheduling
- Introduction to Automation
- Creating Scheduled Tasks
- Using PowerShell for System Administration
- Automating Active Directory Tasks
- Automating Network Tasks
Module 6: PowerShell Remoting
- Introduction to Remoting
- Setting Up Remoting
- Using Invoke-Command
- Session Management
- Security Considerations
Module 7: Advanced PowerShell Features
- PowerShell Profiles
- Customizing the PowerShell Environment
- Creating and Using Classes
- Working with XML and JSON
- Using PowerShell with REST APIs
Module 8: PowerShell and DevOps
- Introduction to DevOps
- Using PowerShell with CI/CD Pipelines
- Infrastructure as Code (IaC)
- Managing Cloud Resources with PowerShell
- PowerShell and Docker