Hi there,
Here is the info I used to get PowerShell and PowerCLI working on my Mac. While it is here for the next time I need it, it is also here in case I helps you. And it was weird. Very weird - as I had to clean up.
We are doing PowerShell 6.0.1 Core and PowerCLI 10.0 on the Mac. If you want to do the same on Centos here is a very good article.
Lets get started.
Cleanup
Because I had the beta builds installed, I thought to clean up first. If you didn’t skip this section.
sudo rm -rf /usr/local/microsoft /Applications/PowerShell.app
sudo rm -f /usr/local/bin/pwsh /usr/local/share/man/man1/pwsh.1.gz
sudo pkgutil -forget com.microsoft.powershell
sudo rm -rf /usr/local/microsoft
sudo rm -f /usr/local/bin/pwsh
You may not need all of those but copy and paste and get it done. BTW, if you want to confirm what packages are installed you can use the following command:
pkgutil -pkgs
HomeBrew
If you don’t have HomeBrew installed you need to install it via these instructions. Is quick and easy. This is a package manager for macOS.
Now you need to open a Terminal window and enter the following:
brew tap caskroom/cask
Brew and PowerShell
The next command is the important one.
brew cask install powershell
So now PowerShell is installed. I open up a new Terminal prompt and type pwsh.
So I have a PowerShell prompt. On a Mac. Nice!
PowerCLI
Now we install PowerCLI.
So while working in PowerShell we enter the following command:
Install-Module -Name VMware.PowerCLI -Scope CurrentUser
When it is finished I type the following command to see what is installed.
Get-Module VMware.* -ListAvailable
Thanks to Alex Lopez I learned another way to do that which is a bit more tidy.
Get-Module “VMware.PowerCLI” -ListAvailable | FT -Autosize
Which looks like this:
I now connect to my vCenter to see how that goes.
Connect-VIserver -server lefroy.thewhites.ca
So I see a bunch of red. Need to get rid of it. You can see the command I use to get rid of it at the bottom of the screen above.
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Now, I try connecting again and even though I am on a Mac look what I see:
Is this nice or what!
One list thing to do - again learned from Alex Lopex is to trust the PowerShell gallery. Is optional but is also nice. The command for that is:
Set-PSRepository -Name “PSGallery” -InstallationPolicy “Trusted”
You should also remember the following command as there are updates to PowerCLI.
update-module
And that command will update any installed modules including PowerCLI.
Upgrading PowerShell
You can upgrade PowerShell - like to 6.1 using the following commands.
brew upgrade
brew cask upgrade powershell
Updates:
- 11/27/18 - changed update to upgrade in the brew - a little nicer as upgrade I think.
- 11/26/18 - some small edits to improve things. Also confirmed the Upgrading PowerShell worked with 6.1. BTW, to confirm that -forget does exist and work use this article.
- 9/16/18 - added the section on updating PowerShell core.
- 5/4/18 - fixed a typo on a command. And added the update info.
- 3/4/18 - I learned some cool things - like the nicer way for version info, and to trust the PowerShell Gallery from Alex Lopez in his article. Lots of good info!
- 3/1/18 - some small edits were needed.
- 2/28/18 - I try this again, with GA PowerShell Core and GA PowerShell 10 and it works!
- 7/23/17 - thanks to Kyle Ruddy I found out that PowerCLI and PowerShell are not yet compatible. Steve suggested I use the Docker image. Good idea!
- 7/23/17 - Done, but it doesn’t work.
I know that this was, or is, a somewhat complicated article for something so simple. But I started with beta of PowerShell core, and PowerCLI on my system and did not want to complicate anything. But it works at the end and I am quite happy with it.
Michael
=== END ===
Few typos in the commands
rm-f should be rm -f (space after rm)
Set_PowerCLIConfiguration -InvalidCertificateAction Ignore
should be
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
This one may be me,
sudo pkgutil –forget com.microsoft.powershell
pkgutil doesn’t have a -forget switch
Thanks Jay,
My template font, makes the space look not there. But will add a note. And thanks for catching the other stuff not sure what happen.
Michael
Hi again Jay, I forgot to say I used the pkgutil with the -forget and it appeared to work and had no error messages. So I think it does have the -forget swtich. I googled and found this article that shows there is a forget switch.
Michael
Great! Thanks a lot!
But its “Set-PowerCLIConfiguration -InvalidCertificateAction Ignore” instead of
“Set_PowerCLIConfiguration -InvalidCertificateAction Ignore”
I think you commented while I was fixing it. But I still appreciate it, so thanks.
Michael