I have looked into this with PowerShell Core 6 and it basically works fine.
To set up the REST API on your local VMware Workstation Pro there is a fine guide on this by VMware: "Use the VMware Workstation Pro REST API Service". You should notice that you have to initialize the API before use. and that the REST API is only active while you have running by the command-tool
vmrest.exe
.There are several independant writings on the VMware REST API, but most are in relation to vCenter where you are working on a remote connection and the security is tighter. When you are working on a local VMWare Workstation you can omit most encryption and work on http direct.
After initializing the REST API there are some PowerShell workarounds to get the credential to work. This is described in detail by others like in the blog entry "Introduction to PowerShell REST API authentication". Most are against vCenter but works on a local VMware Workstation. In my case this works fine:
$Credential = Get-Credential
$Auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Credential.UserName + ':' + $Credential.GetNetworkCredential().Password))
$head = @{
'Authorization' = "Basic $Auth"
}
$RestApiServer = '127.0.0.1:8697'
$BaseUri = "http://$RestApiServer"
To get a list of defined virtual machines one call is enough:
$vmListUri = $BaseUri + '/api/vms'
"URI = $vmListUri" | Write-Debug
$vmList = Invoke-RestMethod -Method Get -Uri $vmListUri -Headers $head
$vmList
Unfortunately it looks like the REST API is rather limited in functionality. By calling the REST API in a web browser it presents the funtionality on virtual macine management like this:
I can create a copy of a existing virtual machine, but not create a new from scratch. This is just one example of features that I miss.
Mayby I should take another look at the VMware VIX API, even it is based on elder technology that fits poorly with PowerShell Core.
No comments:
Post a Comment