iThinkVirtual™

Install PowerShell and VMware PowerCLI on macOS

| 04/03/2018 | Tags: , , , ,

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.

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

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.

brew tap caskroom/cask

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.

brew cask install powershell

Awesome!  Now, to launch a PowerShell session in macOS, enter the following in terminal.

pwsh

Within a PowerShell session, you can check the version of PowerShell by running the following.

$PSVersionTable.PSVersion

As new versions of PowerShell are released, simply update the Homebrew formulae and update PowerShell by running the following commands in terminal.

brew update
brew cask upgrade powershell

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

Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted"

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

Find-Module "VMware.PowerCLI" | Install-Module -Scope "CurrentUser" -AllowClobber

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.

Get-Module "VMware.PowerCLI" -ListAvailable | FT -Autosize

And if you’d like to see all of the VMware installed modules, run the following.

Get-Module "VMware.*" -ListAvailable | FT -Autosize

As new versions of VMware.PowerCLI are released, you can run the following command to update it.

Update-Module "VMware.PowerCLI"

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!

I went ahead and ran the following to ensure the module was imported.  

Import-Module "VMware.PowerCLI"

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…

Connect-VIServer -Server "<Server_Name>"

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.

Set-PowerCLIConfiguration -InvalidCertificateAction "Ignore"

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!

-virtualex-

Pingbacks: Installing PowerShell/PowerCLI on a Mac

macOS 10.13 High Sierra on ESXi 6.5

| 31/12/2017 | Tags: , ,

**NOTE: This is completely for experimental purposes and is unsupported by both Apple and VMware**

Hello all!  This is just a quick follow up to my previous guide on running macOS 10.12 Sierra on ESXi 6.x, where I have now successfully updated the VM to macOS 10.13 High Sierra.

If you simply try to run the upgrade via a self-made ISO, or via the Mac App Store, the final image will fail to boot.  The reason being is because starting with macOS 10.13, Apple has converted the file system from Hierarchical File System Plus (HFS Plus orHFS+) to the new Apple File System (APFS).  During the upgrade process, the HFS+ will be converted to APFS, and the unlocker utility which allows us to even run a macOS VM on ESXi doesn’t support APFS.  In fact, support for ESXi, in general, is no longer available in the latest Unlocker 2.1.1 so I am still using the Unlocker 2.1.0 for ESXi, and Unlocker 2.1.1 for VMware Workstation 14.

For this quick tutorial, I am using the latest VMware ESXi 6.5 Update 1 Build 7388607 and I started by simply cloning my macOS 10.12 VM to a new virtual machine.

Once powered on, go to the Mac App Store and download the macOS High Sierra installation.  When the download is complete, DO NOT run the installer and quit it instead.  You will now have the installer application available in your Applications folder.

Now, open a Terminal session and enter the following command as one line.  Depending on the account you’re are logged in with, sudo may or may not be needed.

sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/startosinstall --converttoapfs NO --agreetolicense --nointeraction

The key argument here is the “–converttoapfs NO” which prevents the OS from converting the drives file system format from HFS+ to APFS.  Additionally, the “–nointeraction” argument is optional.

Now sit back, relax, and let the upgrade do its thing.  When the upgrade is complete, the VM should have successfully booted up and you will now be running macOS High Sierra.

-virtualex

Pingbacks:

Create a macOS/OS X VM on VMware ESXi 6.5 & VMware Workstation 12.x

| 12/02/2017 | Tags: ,

Create a macOS/OS X VM on VMware ESXi 6.5 & VMware Workstation 12.5.2 Pro

 

**NOTE: This is completely for experimental purposes and is unsupported by both Apple and VMware**

Running a MacOS/ OS X virtual machine is not anything new and has been supported for quite some time, as long as you are running said VM on a supported hypervisor with Apple Hardware.  But many of the “Non-Apple” users in the world would not be able to take advantage of this without owning some type of Apple Computer.  Luckily, there is an alternative method for running a Mac-based VM on non-apple hardware-based VMware ESXi and/or VMware Workstation for Windows!  In this tutorial, I am going to show you just how to do so.  Please keep in mind that the methods described in this article are not supported nor endorsed by Apple or VMware in any way, so please use at your own risk.

Before we can begin, there are a few tools required to ensure this works flawlessly.

  • macOS Sierra installation media in .iso format (You can use an older OS as well but for this demo, I will be installing macOS Sierra 10.12.3)
    • This media will have to be created as the OS comes as a .app by default.
    • This link has a good tutorial for creating said media.
  • Unlocker Utility
    • Current Stable version 2.0.8 works up to OS X Yosemite on ESXi 6.0 and Workstation 11
    • Version 2.0.9 RC adds support for macOS Sierra on ESXi 6.5 and Workstation 12.x
  • Type 1 Hypervisor (ESXi) or a Type 2 Hypervisor (VMware Workstation)

 

Ready? Here we go!  I’ll start by showing you how to create a macOS Sierra VM on VMware Workstation 12.5.2 Pro…

VMware Workstation 12.5.2 Pro
  • Make sure that VMware Workstation is installed but not running.
  • Extract the contents on the Unlockler 2.0.9RC.
  • Open a command prompt and navigate to the extracted folder
  • Run win-install.cmd.  This will patch your VMware Workstation to unlock the capabilities to run a Mac OS.  It will also download the latest VMware Tools (darwin.iso) for macOS into the extracted directory.

 

  • Launch VMware Workstation and create the shell VM

  

  • When choosing the hardware compatibility, you can optionally change this to version 10 so that you do not need to manually edit the .vmx file after the shell has been created.

 

  • I am going to leave it at version 12 and manually edit the .vmx file afterwards.  Continue creating your shell by following along…

 

  • Now that we have the shell created, we still need to attach the ISO to the VM.  Click on the CD/DVD (SATA) option on the left side in the Devices pane.  Once in the settings, select the ISO image.

  • Next, navigate to the directory that houses the virtual machine’s files.  Edit the .vmx file with your preferred text editor.  I personally love using NotePad++.  Scroll to the bottom of the text and add the following line.  This will enable the VM to boot up.
    • If you opted to change the hardware version to version 10 in the earlier steps, disregard this and move on to the next step.
smc.version = "0"

  • At this point, the VM is ready to be powered on to install macOS Sierra.  I will cover the installation steps further down in this tutorial, but first, let me cover the procedures for enabling this on ESXi.  I will be showing how to do so on ESXi 6.5a (Build 48872370)

VMware ESXi 6.5a (Build 48872370)

  • For ESXi we first need to copy the unlocker utility to a local or shared datastore.  You can accomplish this by using vCenter, ESXi Host UI, or WinSCP.  For simplicity, I opted to use WinSCP and copied the folder into a newly created “Tools” folder on a local datastore.  You can also take this time to upload the .ISO to the local datastore for use later in this tutorial.

  • Now that the files have been copied, open an SSH connection to your ESXi host, and navigate to the unlocker directory.

  • We can then type “ls” to view the contents of the directory.

  • Next, we must make the installation script executable.  I also like to make the uninstallation script executable as well.  Do so by running the following commands.
chmod +x esxi-install.sh

chmod +x esxi-uninstall.sh

  • Typing “ls” again will now display the (2) scripts in green text, indicating that they are now executable.

  • Run the installer script by running the following command
./esxi-install.sh

  • The script will only take a brief moment to run, afterward, a reboot is required.  Once it has finished type
reboot

  • After the ESXi host has restarted, connect to the ESXi Host UI and begin building the shell VM by following along.

  • Now that the shell VM is created, we need to go back into the VM’s settings and attach the .ISO that you uploaded to the datastore in a previous step.

  • At this point, the VM is ready to be powered on to install macOS Sierra!  Unlike with the VMware Workstation instructions, there is no need to change the hardware version to version 10 or manually modify the .vmx file.

  • In the next section, I will cover the installation steps for MacOS Sierra.
Installing macOS Sierra

**The following instructions apply to both an ESXi and Workstation built macOS VM**

  • Start by powering on the virtual machine and opening the Remote Console view

  • Once the VM has booted the .ISO, you will be presented with this screen.  Click next and then go to the taskbar and open Disk Utility.  We need to create a partition to install macOS onto.

  • After the partition has been created, we can actually start the macOS installation.

  • After the VM has rebooted, we can continue the installation/configuration of macOS.

  • Finally, the macOS VM is ready to use!  For the finishing touches, it is recommended to install VMware Tools on this VM.  When we ran the installation script at the start of this procedure, it downloaded a “tools” folder inside of the unlocker tool folder and inside it contains the darwin.iso which is used to install VMware tools.  This should be the latest release of VMware Tools 10.1.0.  Optionally, you can always download the tools from VMware’s website.
  • In order to install the VMware Tools, we first need to eject the mounted install media.  Afterwards, connect the CD/DVD drive to the darwin.iso file.

  • Once the VMware Tools (darwin.iso) is mounted, double-click the “Install VMware Tools” package to begin the installation.  After it completes, reboot the VM for the changes to take effect.

 

Optional Tweaks
Adjusting Screen Resolution
  • By default, the macOS VM will only support (1) resolution natively, 1024 x 768.  

  • If you’d like to change this to support a higher resolution for say…a larger monitor, please download the following file on the macOS VM.  Once the file has been downloaded to the “Downloads” folder in the VM. Open the “Terminal” application and navigate to the folder.  We need to make the script executable, just as we did earlier with the unlocker scripts.
cd Downloads/VMware-Fix-resolution/

chmod +x vmware-resolutionSet

  • Now we can run the script and specify the desired resolution.  In this example, I am going to choose a 1440 x 900 resolution.  Do so by running the following
./vmware-resolutionSet 1440 900

  • On the ESXi-based VM, I did notice that it does not set a resolution higher than 1176 x 885 while in the Remote Console.  But, the VMware Workstation-based VM does indeed set the desired resolution.

 

Disable Beam Synchronization to Improve VM Performance
  • Download the following application and place it in the “Applications” folder.  Double-click it to launch the application.  Afterwards, add it to the user’s “Logon Option” so it runs every time at login.

I hope that you’ve found this information useful.  Please do leave comments below and subscribe to my blog!  Thanks for stopping by!

-virtualex-

Pingbacks: