VMware Workstation: Using the REST api with powershell


the most did not know that VMware Workstation has a API interface to dealing with it.

The rest api is not enabled by default. The vmrest process must start manually. Start vmrest with the parameter -C to ask for a user and password which must be used to access the api.

Set credentials

D:\> "C:\Program Files (x86)\VMware\VMware Workstation\vmrest.exe" -C

Start Rest Api

D:\> "C:\Program Files (x86)\VMware\VMware Workstation\vmrest.exe"
VMware Workstation R01 REST API
Copyright (C) 2018-2022 VMware Inc.
All Rights Reserved

vmrest 1.2.1 build-20089737
Using the VMware Workstation R01 UI while API calls are in progress is not recommended and may yield unexpected results.
Serving HTTP on

Here you find the documentation

Enter the credentials as defined in the last step and define a HTTP authorization header

$oHeader = @{ "Authorization" = ("Basic {0}" -f ([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(("{0}:{1}" -f $sUser,$sPassword))))) }

Set the content type and passes the header and content type to Invoke-RestMethod. Test it and get a list of all VMs:

$sRequestType = "application/json"
PS D:\> Invoke-RestMethod -Uri http://localhost:8697/api/vms -Method GET -ContentType $sRequestType -Header $oHeader

id                               path
--                               ----
8EOQMINAG9CUDK2A7IVJLL15CS819MFJ C:\Users\Public\Documents\Shared Virtual Machines\Win\Windows 10 x64\Windows 10 x64.vmx
6KEU6BTJQ8KTG91LATPTF81T7BDU40UK C:\Users\Public\Documents\Shared Virtual Machines\Kali\Kali -  OpenVAS.vmx

And get the details of a VM

PS D:\> Invoke-RestMethod -Uri http://localhost:8697/api/vms/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ -Method GET -ContentType $sRequestType -Header $oHeader

or LAN interface

PS D:\> Invoke-RestMethod -Uri http://localhost:8697/api/vms/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ/nic -Method GET -ContentType $sRequestType -Header $oHeader

or the IP Address

PS D:\> Invoke-RestMethod -Uri http://localhost:8697/api/vms/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ/ip -Method GET -ContentType $sRequestType -Header $oHeader



Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.