WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud
  • Tanzu
    • Application Modernization
    • Tanzu services
    • Tanzu Community Edition
    • Tanzu Kubernetes Grid
    • vSphere with Tanzu
  • Home Lab
  • Nested Virtualization
  • Apple
You are here: Home / Apple / VMware Fusion Powershell community module

VMware Fusion Powershell community module

10.05.2017 by William Lam // 1 Comment

During the VMware Fusion 2017 Tech Preview, I was experimenting around with the new Fusion REST API and I had built a small prototype PowerShell Module as a way for me to learn how the API works. This allowed me to provide valuable feedback back to the Fusion Engineering team on improving the REST API UX. I was pleasantly happy to see that the majority of the feedback was indeed implemented for Fusion 10 which GA'ed a few weeks back.

Given the PowerShell module was pretty useful for my own use, I figure I would also publish it for others who might also be interested in Automating VM management using the new Fusion REST API, especially those with a PowerShell/PowerCLI background. Another nice thing about the module is that it can run across macOS/Linux via PowerShell Core or Windows using full blown PowerShell. I have been slowly tweaking the module to include the updated REST API changes and I am please to announce that the VMware.Hosted PowerShell Module which supports the new Fusion 10 REST API is now available!

The module includes the following 14 functions:

  • Connect-HostedServer
  • Disconnect-HostedServer
  • Get-HostedNetworks
  • Get-HostedVM
  • Get-HostedVMNic
  • Get-HostedVMSharedFolder
  • New-HostedVM
  • New-HostedVMSharedFolder
  • Remove-HostedVM
  • Remove-HostedVMSharedFolder
  • Resume-HostedVM
  • Start-HostedVM
  • Stop-HostedVM
  • Suspend-HostedVM


If you have ever used PowerCLI before, these functions should feel very familiar. We have basic Connect/Disconnect-HostedServer which will set an environmental variable called $DefaultHostedServer. This variable contains some basic information about the Fusion API endpoint as well as the base64 encoded credentials which are required when connecting to the new Fusion API. Below are a few examples using the new Fusion module, they are pretty basic and I have only implemented a sub-set of the Fusion REST API, so any community contributions are most welcome!

Lets connect to the Fusion 10 REST API endpoint remotely using the Connect-HostedServer function, which means HTTPS will need to be setup (see this blog post here for details):

Connect-HostedServer -Server 172.16.1.1 -Protocol https -Username vmware -Password '[email protected]'


Next, we can get a list of all VMs that are registered with our Fusion instance by using the Get-HostedVM function:

Get-HostedVM

To get more details about a specific VM, we can also pass in the VM's Id as shown in the screenshot:

Get-HostedVM -Id 1TS7DAP


Today, the REST API only allows for Cloning from an existing (poweredOff VM), so lets try that out using the New-HostedVM function which accepts the Id of an existing VM and the new name for the cloned VM:

New-HostedVM -ParentId 1tS7DAP -Name Photon-Clone

To power on the VM, we simply use the Start-HostedVM and passing in the Id of the VM:

Start-HostedVM -Id 1CW6DN

Now that the VM is powered on, we can retrieve more details such as the power state and the IP Address of the VM by running the Get-HostedVM function:

Get-HostedVM -Id 1CW6DN


I personally make use of the Shared Folders feature in Fusion, so I created a few functions to allow you to retrieve, configure and remove shared folders for a given VM.

To create a new shared folder mapping, we can use the New-HostedVMSharedFolder function and providing the Id of the VM, the name of the folder inside of the VM and the full host path that we wish to share within the VM:

New-HostedVMSharedFolder -Id 1CW6DN -FolderName Downloads -HostPath /Users/lamw/Downloads

As you can see in the example below, I created two shared folders and we can list all shared folders for a given VM by simply running:

New-HostedVMSharedFolder -Id 1CW6DN


Finally, we can also list all VM Networks that have been defined in Fusion and their configurations by using the Get-HostedNetworks command as shown in the screenshot below:


There are several other functions that I did not cover, but hopefully you will find that they are pretty easy and intuitive to use. Since this a community and non-official VMware module, if folks would like to contribute and add other functionality or even improve the current implementation, feel free to send me a pull request.

More from my site

  • VMware Fusion 2017 Tech Preview adds REST API support
  • Workspace One Access (vIDM) Powershell Module to automate creating 3rd Party Identity Provider
  • Managing Distributed Firewall Rules in VMC using PowerShell & NSX-T Policy API
  • Native OVF support for Fusion/Workstation 2017 Tech Preview 
  • Heads Up - Workaround for changing Mac OS X VM display resolution in vSphere & Fusion

Categories // Apple, Automation, Fusion, PowerCLI Tags // apple, fusion, powershell, PowerShellCore, REST API, vmrest

Comments

  1. Colin Westwater says

    10/05/2017 at 7:37 am

    I hope the REST API will be available in Workstation at some point. I found a thread on VMTN that they hope it will come, so fingers crossed!

    Reply

Thanks for the comment! Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Author

William Lam is a Senior Staff Solution Architect working in the VMware Cloud team within the Cloud Infrastructure Business Group (CIBG) at VMware. He focuses on Cloud Native technologies, Automation, Integration and Operation for the VMware Cloud based Software Defined Datacenters (SDDC)

Connect

  • Email
  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Vimeo

Recent

  • Changing the default HTTP(s) Reverse Proxy Ports on ESXi 8.0 03/22/2023
  • Quick Tip - How to download ESXi ISO image for all releases including patch updates? 03/15/2023
  • SSD with multiple NVMe namespaces for VMware Homelab 03/14/2023
  • Is my vSphere Cluster managed by vSphere Lifecycle Manager (vLCM) as a Desired Image or Baseline? 03/10/2023
  • Interesting VMware Homelab Kits for 2023 03/08/2023

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2023

 

Loading Comments...