Jun 21, 2020. Apr 23, 2014.
As you have probably heard by now, Microsoft has just open-sourced PowerShell and made it available for Linux and Mac OS X. In this blog post, I will take you through the steps to download, install and run PowerShell on a Mac.
Download and Install PowerShell for Mac OX
- Go to PowerShell github project: https://github.com/PowerShell/PowerShell
- Scroll down to the Get PowerShell section and download .pkg:
3. Locate the newly downloaded file in Downloads, right-click it and click Open:
4. You will be warned that this is a file from the Internet and then prompted for your local administrative password, then go through the installation wizard.
Run PowerShell on Mac OS X
PowerShell is a command-prompt in your terminal window, so to start it:
- Start the Terminal application,
- Now you can simply type powershell as a command and this will start the PowerShell engine and move you from the bash prompt ($) to the PowerShell prompt (PS):
- That is it! You can now type a PowerShell command and see the output. For example, here’s Get-Process:
If you are new to PowerShell, see the Learning PowerShell page on GitHub.
Just a few days ago, PowerShell Core v6.0 was released for Windows, Linux, and macOS systems. Alongside this release came the release of VMware PowerCLI 10.0.0.78953 which is VMware’s own “PowerShell-like” utility. In this post, I am going to show how to install both on to a macOS system. Let’s get to it!
There are a few prerequisites needed before PowerShell can be installed on macOS which I will cover, and they are as follows:
- Homebrew – Homebrew installs the stuff you need that Apple didn’t.
- Homebrew-Cask – extends Homebrew and brings its elegance, simplicity, and speed to macOS applications and large binaries alike.
- Xcode Command Line Tools
Per the instructions on the Homebrew site, copy and paste the following command into a terminal window to install Homebrew.
This will prompt you to press Enter to continue and the prompt you to enter your password. It will also check if Xcode command line tools are installed, and if not, it will download and install it for you before completing the installation of Homebrew. Nice!
Now, the next step is to install Homebrew-Cask and per its sites installation notes, copy and paste the following command into a terminal window.
Great! With the prerequisites complete, it’s time to install PowerShell Core 6.0.1. Run the following command to do so and enter your password when prompted.
Awesome! Now, to launch a PowerShell session in macOS, enter the following in terminal.
Within a PowerShell session, you can check the version of PowerShell by running the following.
As new versions of PowerShell are released, simply update the Homebrew formulae and update PowerShell by running the following commands in terminal.
While leveraging Homebrew is the recommended installation method, there are alternate methods as well. For more information on that along with uninstallation commands, please see the following link.
Congratulations! You’ve successfully installed PowerShell Core 6.0.1 onto macOS! Next comes the fun stuff for us VMware enthusiasts, installing VMware PowerCLI from the “PSGallery”. Let’s continue!
Since VMware PowerCLI has moved from being its own native installer to the PSGallery, the PSGallery needs to be “Trusted” before anything from it can be installed. To trust the PSGallery, entering the following command in the PowerShell session.
Note: This is optional and if it is skipped, you will be prompted to trust the gallery when entering the PowerCLI module install command
Next, run the following command to install the VMware.PowerCLI module. This will find and install the latest version of the module available in the PSGallery
Note: Alternatively, you could set the “-Scope” parameter to “AllUsers” and if you wanted to install a different version you could use the “-RequiredVersion” parameter and specify the version number.
Once this finishes, we can check to make sure the module is installed by running the following command.
And if you’d like to see all of the VMware installed modules, run the following.
As new versions of VMware.PowerCLI are released, you can run the following command to update it.
With VMware.PowerCLI now installed, you can connect to your vCenter Server or ESXi host and begin using its cmdlets to obtain information or automate tasks!
Osx Powershell
I went ahead and ran the following to ensure the module was imported.
Powershell For Mac
I noticed one caveat, the SRM module does not seem to be supported in PowerShell Core, so I hope that gets resolved soon.
Let’s test connecting to vCenter server…
I also noticed an error when running the above command stating that the “InvalidCertificateAction” setting was “Unset” and not supported.
To bypass this, enter the following command and then enter “Y” when prompted. This will set the parameter for the current user.
Note: Alternatively, you can also use the “-Scope” parameter and enter “Session”, “User”, or “AllUsers” to apply the setting to those options respectively.
Now, if we try to connect to vCenter again, we should be successful.
Well, that about does it! I hope that you have found this post useful and I thank you for stopping by and reading my content. I’d like to give a shoutout to Mike White for his post on the same topic. Until next time!
Powershell Os Version
-virtualex-
Pingbacks: Installing PowerShell/PowerCLI on a Mac
Install PowerShell and VMware PowerCLI on macOS by virtualex is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.