Hi,
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
1 | D:\> "C:\Program Files (x86)\VMware\VMware Workstation\vmrest.exe" -C |
Start Rest Api
1 2 3 4 5 6 7 8 9 10 11 | 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 127.0.0.1:8697 - |
Here you find the documentation
Enter the credentials as defined in the last step and define a HTTP authorization header
1 2 3 | $sUser =myUser $sPassword =mySecretPassword $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:
1 2 3 4 5 6 7 | $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
1 | PS D:\> Invoke-RestMethod -Uri http://localhost:8697/api/vms/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ -Method GET -ContentType $sRequestType -Header $oHeader |
or LAN interface
1 | PS D:\> Invoke-RestMethod -Uri http://localhost:8697/api/vms/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ/nic -Method GET -ContentType $sRequestType -Header $oHeader |
or the IP Address
1 2 3 4 5 | PS D:\> Invoke-RestMethod -Uri http://localhost:8697/api/vms/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ/ip -Method GET -ContentType $sRequestType -Header $oHeader ip -- 192.168.254.1 |
Michael