Microsoft’s PowerShell, initially a Windows only command line shell and scripting language has transformed into a cross-platform management tool that is now available on macOS and Linux.
macOS lacks an industry standard scripting language for systems management, with PowerShell expanding it is more than capable of filling that void. Also for IT Professionals it allows for you to carry your windows system administration skills into any endpoint - You can now trade that dell laptop in for a new macbook and not miss a beat.
Future articles will show examples of how you can utilize PowerShell in macOS.
Installing Homebrew and PowerShell on macOS
Easiest way to install PowerShell and keep it updated in current is to use Homebrew. Homebrew is a free and open-source package management tool that simplifies the installation of software on macOS and linux.
First lets check and see if PowerShell is already installed on your system. From a terminal window enter the following:
pwsh
If PowerShell is installed you will see the following and you can skip the section on installing PowerShell.
Next lets test to see if Homebrew is installed. From a terminal window type the following:
brew
If it is installed you will see the following response:
Installing Homebrew
To install homebrew on your macOS run the following command from a terminal window. If this asks you for sudo access, just re-authenticate with an account that has administrator access on your mac:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Installing PowerShell
From the same terminal window, run the following command:
brew install powershell
To validate that powershell is installed correctly, type pwsh
in the terminal window and you will get the following response:
Updating Brew and PowerShell
It’s important to stay updated as new releases of software are released. In order to upgrade both Brew and PowerShell, you can enter the following commands in the terminal window. Mine is currently up to date, so the responses are a little bit different
brew update
brew upgrade powershell
First Example of PowerShells power(pun intended).
Ever wanted to see what exactly chrome was doing on your system. In terminal type pwsh and then cut and paste the following code:
Get-process | Where-Object { $_.ProcessName -like '*Chrome*' } | format-list ProcessName,VirtualMemorySize, ID
In the next article we will break down this and a few more powershell scripts on the mac.