{"id":9134,"date":"2022-12-06T22:59:32","date_gmt":"2022-12-06T21:59:32","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=9134"},"modified":"2024-07-23T23:03:53","modified_gmt":"2024-07-23T21:03:53","slug":"vmware-workstation-using-the-rest-api-with-powershell","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/vmware-workstation-using-the-rest-api-with-powershell\/","title":{"rendered":"VMware Workstation: Using the REST api with powershell"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_9134 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_9134')){$('.twoclick_social_bookmarks_post_9134').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"VMware%20Workstation%3A%20Using%20the%20REST%20api%20with%20powershell\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Athe%20most%20did%20not%20know%20that%20VMware%20Workstation%20has%20a%20API%20interface%20to%20dealing%20with%20it.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/vmware-workstation-using-the-rest-api-with-powershell\\\/\",\"post_id\":9134,\"post_title_referrer_track\":\"VMware+Workstation%3A+Using+the+REST+api+with+powershell\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>the most did not know that VMware Workstation has a API interface to dealing with it.<br \/>\n<!--more--><\/p>\n<p>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.<\/p>\n<p>Set credentials<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nD:\\&gt; &quot;C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmrest.exe&quot; -C\r\n<\/pre>\n<p>Start Rest Api<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nD:\\&gt; &quot;C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmrest.exe&quot;\r\nVMware Workstation R01 REST API\r\nCopyright (C) 2018-2022 VMware Inc.\r\nAll Rights Reserved\r\n\r\nvmrest 1.2.1 build-20089737\r\n-\r\nUsing the VMware Workstation R01 UI while API calls are in progress is not recommended and may yield unexpected results.\r\n-\r\nServing HTTP on 127.0.0.1:8697\r\n-\r\n<\/pre>\n<p><a href=\"https:\/\/developer.vmware.com\/apis\/412\/vmware-workstation-pro-api#\/VM%20Management\" rel=\"noopener\" target=\"_blank\">Here <\/a>you find the documentation<\/p>\n<p>Enter the credentials as defined in the last step and define a HTTP authorization header<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$sUser=myUser\r\n$sPassword=mySecretPassword\r\n$oHeader = @{ &quot;Authorization&quot; = (&quot;Basic {0}&quot; -f (&#x5B;System.Convert]::ToBase64String(&#x5B;System.Text.Encoding]::UTF8.GetBytes((&quot;{0}:{1}&quot; -f $sUser,$sPassword))))) }\r\n<\/pre>\n<p>Set the content type and passes the header and content type to Invoke-RestMethod. Test it and get a list of all VMs:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$sRequestType = &quot;application\/json&quot;\r\nPS D:\\&gt; Invoke-RestMethod -Uri http:\/\/localhost:8697\/api\/vms -Method GET -ContentType $sRequestType -Header $oHeader\r\n\r\nid                               path\r\n--                               ----\r\n8EOQMINAG9CUDK2A7IVJLL15CS819MFJ C:\\Users\\Public\\Documents\\Shared Virtual Machines\\Win\\Windows 10 x64\\Windows 10 x64.vmx\r\n6KEU6BTJQ8KTG91LATPTF81T7BDU40UK C:\\Users\\Public\\Documents\\Shared Virtual Machines\\Kali\\Kali -  OpenVAS.vmx\r\n\r\n<\/pre>\n<p>And get the details of a VM<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\&gt; Invoke-RestMethod -Uri http:\/\/localhost:8697\/api\/vms\/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ -Method GET -ContentType $sRequestType -Header $oHeader\r\n<\/pre>\n<p>or LAN interface<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\&gt; Invoke-RestMethod -Uri http:\/\/localhost:8697\/api\/vms\/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ\/nic -Method GET -ContentType $sRequestType -Header $oHeader\r\n<\/pre>\n<p>or the IP Address<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS D:\\&gt; Invoke-RestMethod -Uri http:\/\/localhost:8697\/api\/vms\/8EOQMINAG9CUDK2A7IVJLL15CS819MFJ\/ip -Method GET -ContentType $sRequestType -Header $oHeader\r\n\r\nip\r\n--\r\n192.168.254.1\r\n\r\n<\/pre>\n<p>Michael<\/p>\n<p><!-- https:\/\/communities.vmware.com\/t5\/VMware-PowerCLI-Discussions\/invoke-restmethod-to-use-vsphere-rest-apis\/td-p\/1832677 --> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, the most did not know that VMware Workstation has a API interface to dealing with it.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[239,1946,1945,893],"class_list":["post-9134","post","type-post","status-publish","format-standard","hentry","category-vmware","tag-api","tag-invoke-restmethod","tag-rest","tag-vmware-workstation"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=9134"}],"version-history":[{"count":5,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9134\/revisions"}],"predecessor-version":[{"id":9137,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/9134\/revisions\/9137"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=9134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=9134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=9134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}