What is PowerShell and How to Install PowerShell on Windows, Linux, and macOS?

PowerShell is a powerful and versatile scripting language and automation framework developed by Microsoft. It was first introduced in 2006 and has since become an integral part of Windows operating systems. PowerShell is designed to help IT professionals and system administrators automate tasks, manage system configurations, and perform various administrative functions across Windows-based systems.

PowerShell
PowerShell

Microsoft PowerShell is a built-in framework (command line interpreter) for Windows-based systems and provides granular control over managing and automating Windows systems. As a result, it is also frequently used by cybercriminals. Understanding PowerShell and how potential attacks can be carried out using PowerShell is essential for organizations to defend against PowerShell attacks.

Key Characteristics and Features of PowerShell

  1. Command-Line Interface (CLI): PowerShell provides a command-line interface where users can interact with the system and perform tasks by typing commands. These commands are called cmdlets (pronounced “command-lets”), and they are designed to be consistent and easy to use.
  2. Scripting Language: In addition to its interactive CLI, PowerShell is a full-fledged scripting language. Users can write scripts, which are collections of cmdlets and logic, to automate complex tasks, perform system administration, or even create custom tools.
  3. Object-Oriented: PowerShell is object-oriented, which means that the data it works with is represented as objects with properties and methods. This object-oriented approach makes it easier to manipulate and work with data in a structured manner.
  4. Extensibility: PowerShell can be extended with modules, which are collections of cmdlets, scripts, and functions that provide additional functionality. Microsoft and third-party developers create modules to enhance PowerShell’s capabilities for specific tasks and technologies.
  5. Remote Management: PowerShell supports remote management, allowing administrators to execute commands and scripts on remote computers and servers. This is particularly useful for managing large-scale networks and cloud-based resources.
  6. Integration with .NET: PowerShell is tightly integrated with the .NET Framework, which means users can access and leverage .NET classes and libraries within their scripts, enhancing its capabilities for more advanced tasks.
  7. Security: PowerShell has security features in place to help prevent the execution of malicious scripts. It includes execution policies that control whether scripts are allowed to run and can be configured to restrict the execution of unsigned or untrusted scripts.
  8. Cross-Platform: While PowerShell was initially developed for Windows, it has expanded to support other platforms through PowerShell Core, which is an open-source, cross-platform version of PowerShell. This allows users to work with PowerShell on Linux and macOS systems.

PowerShell is widely used for various administrative tasks, such as managing system configurations, automating routine processes, troubleshooting issues, and performing tasks in Active Directory, Exchange, and other Microsoft technologies. Its scripting capabilities and extensibility make it a valuable tool for IT professionals and system administrators.

Installing PowerShell on Windows

Windows PowerShell
Windows PowerShell

There are multiple ways to install PowerShell in Windows. Each install method is designed to support different scenarios and workflows. Choose the method that best suits your needs.

  • Winget – Recommended way to install PowerShell on Windows clients
  • MSI package – The best choice for Windows Servers and enterprise deployment scenarios
  • ZIP package – The easiest way to “side load” or install multiple versions, Use this method for Windows Nano Server, Windows IoT, and Arm-based systems
  • .NET Global tool – A good choice for .NET developers that install and use other global tools
  • Microsoft Store package – An easy way to install for casual users of PowerShell but has limitations

 

Installing PowerShell on macOS

Mac PowerShell
Mac PowerShell

There are several ways to install PowerShell on macOS. Choose one of the following methods:

 

Install PowerShell on Linux

Linux PowerShell
Linux PowerShell

PowerShell can be installed on several different Linux distributions. Most Linux platforms and distributions have a major release each year, and provide a package manager that’s used to install PowerShell. PowerShell can be installed on some distributions of Linux that aren’t supported by Microsoft. In those cases, you may find support from the community for PowerShell on those platforms.

  • Alpine
  • Debian
  • Red Hat Enterprise Linux (RHEL)
  • Ubuntu

Community supported distributions
PowerShell can be installed on many distributions of Linux that aren’t supported by Microsoft. In those cases, you may find support from the community for PowerShell on those platforms

To be supported by Microsoft, the Linux distribution must meet the following criteria:

  • The version and architecture of the distribution is supported by .NET Core.
  • The version of the distribution is supported for at least one year.
  • The version of the distribution isn’t an interim release or equivalent.
  • The PowerShell team has tested the version of the distribution.

Alternate installation methods

There are three other ways to install PowerShell on Linux, including Linux distributions that aren’t officially supported. You can try to install PowerShell using the PowerShell Snap Package. You can also try deploying PowerShell binaries directly using the Linux tar.gz package.

What is PowerShell Modules How to Install PowerShell Modules?

PowerShell module contains a set of related Windows PowerShell members such as cmdlets, providers, functions, workflows, variables, and aliases. The members of a package (which are usually grouped in a single directory) can be implemented in a PowerShell script, a compiled DLL, or both. The primary objective of a module is to allow the modularization of Windows PowerShell code.

By defining a set of related script files, assemblies, and related resources as a module, you can reference, load, persist, and share your code much more easily than you would otherwise. For example, people who write commands can use modules to organize their commands and share them with others, while those who receive modules can add the commands in the modules to their PowerShell sessions and use them just like the built-in commands.

PowerShell Module Components and Types

A module comprises four essential components, which include a PowerShell script or a managed cmdlet assembly, additional assemblies or scripts, a manifest file, and a directory that contains all of those contents. The following sections describe the types of modules you can get by mixing and matching the different possible parts of a module together:

Script Modules: A script module is simply a Windows PowerShell script with a .psm1 extension, which allows administrators to use import, export, and management functions on it. A script module contains valid Windows PowerShell code. It can be saved or installed on the PowerShell module path or any path that you explicitly describe so that PowerShell can reasonably discover it.
Binary Modules: A binary module is a .NET Framework assembly (.dll) that contains compiled code. Compared to a script module, a binary module allows you to create cmdlets faster or use features such as multithreading that are not as easy to code in Windows PowerShell scripts. In addition, a binary module can be saved or installed in a folder along the PowerShell module path.
Manifest Modules: A manifest module is a module that uses a manifest file to describe all of its component binary modules but doesn’t have any sort of core assembly or script.
Dynamic Modules: A dynamic module is a module that is not loaded from, or saved to, a file. Instead, they are created dynamically by a script, using the New-Module cmdlet. This module enables a script to create a module on demand that does not need to be loaded or saved to persistent storage. Dynamic modules do not require permanent folders to store their related assemblies.

Conclusion

PowerShell can be installed on Windows by first moving towards the “Microsoft Store” and there look for the PowerShell. When found just click on the “Get” button to install PowerShell. It can also be installed via the GitHub repository or CMD. This write-up demonstrated the procedure for installing PowerShell on Windows.