You can use the vSphere Guest Operations API or the PowerCLI Invoke-VMScript and Copy-VMGuestFile cmdlet in your customization workflows.

Before you can use the vSphere Guest Operations API either directly or via PowerCLI, you need to set up Direct Connect or a Compute VPN and a management network a firewall rule allowing traffic to ESXi hosts on port 443.

Prerequisites

Procedure

  1. Verify that the VM is running the latest version of VMware Tools.
  2. Verify that you can access the Guest Operations API, either directly or via a simple PowerCLI cmdlet.

    You could use a cmdlet like this one to test your ability to reach port 443 on the ESXi host with IP address 10.100.1.1.

    PS C:\Users\admin>Test-NetConnection -Port 443 -ComputerName 10.100.1.1

    A response of True or TcpTestSucceeded indicates a successful test.

Using the PowerCLI Invoke-VMScript Cmdlet

After you establish a network connection that allows traffic to port 443 on your hosts, you can use the Guest Operations API directly, or via PowerCLI as shown here. API and cmdlet requests go to port 443 on the host where the subject VM (Win10-Example here) is running. VMware Tools running on the VM handles the requested guest operations.

PS C:\Users\admin> $vm = Get-VM Win10-Example
PS C:\Users\admin> Invoke-VMScript -ScriptText "dir C:\" -VM $vm -GuestUser admin -GuestPassword $passwd"

ScriptOutput
------------------------------------------------------
|
| Directory: C:\
|
| ...