Install PowerCLI on Mac, start using PowerNSX

This is something I've been wanting to publish for a while, and finally my Mac got formatted (no questions will be taken at this point...) and I had to re-install it all, and I just couldn't find the instructions on how to do it without just having to read pages and pages of disclaimers and stuff...

Why PowerCLI? Cause it's a simplest way to automate your vCenter tasks, via the command line, fast and furious. Sure, one day a working vCenter web plugin will come, but who knows when...

Why PowerNSX? Same... but for the NSX admins. Trust me, my life got so much better the day I stopped depending on vCenter Web GUI.

How do I install and start using it? Simple. Just follow this 5 Steps guide...


Step 1: Install PowerShell (check the update below first!!!)

Make sure you have GitHub:

# git

Clone the PowerShell installation package from GitHub:
# git clone --recursive https://github.com/PowerShell/PowerShell

Once you got it, enter the Folder, and install the package (you'll be asked for a Password a few times):
Submodule path 'src/libpsl-native/test/googletest': checked out 'c99458533a9b4c743ed51537e25989ea55944908'


MatBook-Pro:~ mjovanovic$ cd /Users/mjovanovic/PowerShell
MatBook-Pro:PowerShell mjovanovic$ ./tools/install-powershell.sh

Get-PowerShell Core MASTER Installer Version 1.1.1
Installs PowerShell Core and Optional The Development Environment

Run "pwsh" to start a PowerShell session.
*** NOTE: Run your regular package manager update cycle to update PowerShell Core
*** Install Complete


MatBook-Pro:PowerShell mjovanovic$ pwsh
PowerShell v6.0.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /Users/mjovanovic/PowerShell>

You're in the PowerShell!!!

UPDATE: As of December 2018, this method is no longer supported. You'd actually get into a quite "nifty" catch 22, where PowerShell 6.1.1 doesn't support most of relevant PowerCLI Commands, New PowerCLI doesn't support anything under 6.0.5, and some PowerNSX Commands require 6.0.1 and above. Awesome!

SOLUTIONDownload PowerShell 6.0.5, that one works! Download it as a package, and install. The rest of the post remains the same.



Step 2: Install PowerCLI

Now lets procede with the PowerCLI. More details on this Link, if you happen to need more details... but basically all you need is the following command: https://blogs.vmware.com/PowerCLI/2018/03/installing-powercli-10-0-0-macos.html


PS /Users/mjovanovic/PowerShell> Install-Module -Name VMware.PowerCLI -Scope CurrentUser

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install
the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y


Step 3: Install PowerNSX Modules

Ok, so now we just need to install the PowerNSX Modules:

PS /Users/mjovanovic/PowerShell> Find-Module PowerNSX | Install-Module -scope CurrentUser

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install
the modules from 'https://www.powershellgallery.com/api/v2/'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

Step 3.1: Resolve the Certificate Error:
If you tried to connect to your vCenter now, you´d get this error:
Connect-VIServer : 06/08/2018 18:32:43 Connect-VIServer Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Ignore to ignore the certificate errors for this connection.

Before Logging in to your vCenter, to avoid the Certificate problems (which you will most definitely have), first use, You need to set the Certificate Errors to FALSE:

PS /Users/mjovanovic/PowerShell> set-PowerCLIConfiguration -InvalidCertificateAction Ignore

Perform operation?
Performing operation 'Update PowerCLI configuration.'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

PS /Users/mjovanovic/PowerShell>


Step 4: Log into the NSX Manager and vCenter

Now you are GOOD TO DO, you can Log in to your NSX, and to the vCenter:

PS /Users/mjovanovic/PowerShell> Connect-NsxServer -NsxServer 10.20.70.18 -Username admin -Password M4TSCL0UD

PowerNSX requires a PowerCLI connection to the vCenter server NSX is registered against for proper operation.
Automatically create PowerCLI connection to 10.20.70.37?
[Y] Yes  [N] No  [?] Help (default is "Y"): Y

WARNING: Enter credentials for vCenter 10.20.70.37

PowerShell credential request
Enter your credentials.
User: administrator@vsphere.local
Password for user administrator@vsphere.local: **************

Version             : 6.4.0
BuildNumber         : 7564187
Credential          : System.Management.Automation.PSCredential
Server              : 10.20.70.18
Port                : 443
Protocol            : https
UriPrefix           :
ValidateCertificate : False
VIConnection        : 10.20.70.37
DebugLogging        : False
DebugLogfile        : \PowerNSXLog-admin@10.20.70.18-2018_06_08_18_37_32.log


Step 5: Start using PowerNSX

You can do so many things here! I recommend this Guide to get you started:
https://www.vmware.com/content/dam/digitalmarketing/vmware/en/pdf/products/nsx/vmware-automating-vsphere-with-powernsx.pdf

Most important command:
PS /Users/mjovanovic> get-command -module PowerNSX                                                                                                                                 

CommandType     Name                                               Version    Source                                                                                              
-----------     ----                                               -------    ------                                                                                              
Function        Add-NsxDynamicCriteria                             3.0.1118   PowerNSX                                                                                            
Function        Add-NsxDynamicMemberSet                            3.0.1118   PowerNSX                                                                                            
Function        Add-NsxEdgeInterfaceAddress                        3.0.1118   PowerNSX                                                                                            
Function        Add-NsxFirewallExclusionListMember                 3.0.1118   PowerNSX                                                                                            
Function        Add-NsxFirewallRuleMember                          3.0.1118   PowerNSX                                                                                            
Function        Add-NsxIpSetMember                                 3.0.1118   PowerNSX                                                                                            
Function        Add-NsxLicense                                     3.0.1118   PowerNSX                                                                                            
Function        Add-NsxLoadBalancerPoolMember                      3.0.1118   PowerNSX                                                                                            
Function        Add-NsxLoadBalancerVip                             3.0.1118   PowerNSX                                                                                            

Function        Add-NsxSecondaryManager                            3.0.1118   PowerNSX                     
...

Just play around with these!

Most Popular Posts