LogicMonitor seeks to disrupt AI landscape with $800M strategic investment at $2.4B valuation to revolutionize data centers.

Learn More

Installing PowerShell on macOS

The object of this article is to demonstrate methods to test and debug PowerShell scripts from your workstation. Using this method does not require a remote desktop session. Having PowerShell installed locally is a useful tool when writing or troubleshooting scripts for Windows instances. Having the Mac version of PowerShell provides the same benefits as using the Integrated Scripting Environment (ISE) that is available on Windows systems. This includes the auto-complete feature (intlisense), and the ability to apply color-coded syntax.

Installation

Disclaimer: PowerShell for Mac does not include some of the Windows specific cmdlets (including WIMObject and CIMInstances), so it may not be possible to use these objects for testing.

The install process is simple, all you need is a terminal session from your Mac, and MacOS build 10.12 or higher. All of the commands listed below should be run within the MacOS terminal.

1. Start by installing Homebrew:

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

2. Install Homebrew-Cask so additional packages can be installed:

brew tap caskroom/cask

3. Now for PowerShell:

brew cask install powershell

Note: The PowerShell formula for Homebrew includes OpenSSL as a dependency. “On macOS, .NET Core requires Homebrew’s OpenSSL because the “OpenSSL” system libraries on macOS are not OpenSSL, as Apple deprecated OpenSSL in favor of their own libraries. This requirement is not a hard requirement for all of PowerShell. However, most networking functions (such as Invoke-WebRequest) do require OpenSSL to work properly.”

PowerShell can be installed without OpenSSL, but some functionality may be lost. Here are the steps to install PowerShell without OpenSSL.

Updating

When a new version of PowerShell is released, simply update Homebrew and then upgrade PowerShell with these commands:

brew update
brew cask reinstall powershell

Note: At the time this article was authored, there is a known defect in Cask. At present, PowerShell must be completely reinstalled to upgrade to a newer version.

Verification and Testing

The PowerShell installation can be verified and tested within VisualStudio. The Mac version can be downloaded here.

Once VisualStudio Code has been installed, launch the application and add the PowerShell extension.

1. Open VScode

2. Click the highlighted icon referenced below:

3. Search for PowerShell and install the one from Microsoft

4. Once installed, click the “Reload” button so the extension loads

5 .To verify that PowerShell has been properly installed, open any *.ps1 script. New scripts can also be created here.

Uninstallation

PowerShell can be uninstalled from the terminal with the following Homebrew command:

brew cask uninstall powershell

Feel free to browse our Community Exchange for more PowerShell-based LogicModule examples.

Troubleshooting and common issues

Even with clear instructions, you may encounter some issues when installing and setting up PowerShell on macOS. Below are common problems and their solutions:

  • PowerShell fails to launch after installation: If PowerShell doesn’t start after installation, ensure that the installation directory is included in your system’s PATH. You can verify this by running echo $PATH in the terminal. If the path to PowerShell isn’t listed, add it manually to your .zshrc or .bash_profile.
  • Permission denied errors: If you encounter permission-related errors during installation or execution, ensure that you have the necessary administrative privileges. You may need to prepend sudo to your commands to execute them with elevated permissions.
  • Incompatible .NET core version: PowerShell requires a specific version of .NET Core to run. If you receive errors related to .NET, check the version installed on your system by running dotnet –version and compare it with the version required by PowerShell. If there’s a mismatch, install the correct version using Homebrew or by downloading it directly from the .NET website.
  • Modules failing to import: Some PowerShell modules may not be available on macOS or may require additional dependencies. If a module fails to import, verify that it’s compatible with PowerShell Core and macOS. You can often resolve these issues by updating PowerShell or installing the necessary dependencies via Homebrew.
  • Slow performance: If you notice that PowerShell is running slowly on macOS, check for background processes that might be consuming resources. Additionally, ensure that you are running the latest version of PowerShell, as updates often include performance improvements.

By addressing these common issues, you can ensure a smoother experience when using PowerShell on macOS.

Unlock the full potential of PowerShell on macOS

PowerShell on macOS opens up a world of possibilities for automating tasks and managing your systems more efficiently across your varying platforms. This guide helps you get PowerShell on your Mac back up and running quickly so that you can reap the full potential of the tool.

If you’re looking for more ways to leverage PowerShell within your environment, feel free to browse our Community Exchange for a variety of PowerShell-based LogicModule examples. There, you can find and share scripts, modules, and best practices to further enhance your IT management and automation strategies.

Subscribe to our blog

Get articles like this delivered straight to your inbox