0

This is a VM I created using Terraform

When I run the command Get-VM "VMNAME" it works without a problem and it returns the vm info, but when i run Invoke-GetVmPower -Vm "test_machine_vm_01_output" it return the following error

Invoke-vSphereApiClient : InvocationException: [NOT_FOUND]
Virtual machine with identifier 'test_machine_vm_01_output:UUID' does not exist.
The object 'vim.ManagedEntity:test_machine_vm_01_output' has already been deleted or has not been completely created
 ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
   --- End of inner exception stack trace ---
At C:\Program Files\WindowsPowerShell\Modules\VMware.Sdk.vSphere.vCenter.Vm\1.0.110.20624081\Api\PowerApi.ps1:507
char:33
+                 $invokeResult = Invoke-vSphereApiClient @invokeParams
+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-vSphereApiClient

I can start the VM without any issue if i do it from Vcenter

The OS is RHEL7 not windows

Danilo Patrucco
  • 110
  • 3
  • 10

2 Answers2

1

https://developer.vmware.com/apis/vsphere-automation/latest/vcenter/api/vcenter/vm/vm/power/get/ String vm

Virtual machine identifier. The parameter must be an identifier for the resource type: VirtualMachine.

maybe it will work:

$UUID = (Get-View (get-vm VMname).id).config.UUID
Invoke-GetVmPower -Vm $UUID 
rinat gadeev
  • 114
  • 4
  • same issue, it does get the id of the vm without any issue, but it fail with the invoke-GetVmPower command, and i can echo out the id without any issue – Danilo Patrucco Feb 15 '23 at 15:05
  • @DaniloPatrucco Get-VM "VMNAME" | Invoke-GetVmPower ? – rinat gadeev Feb 16 '23 at 04:37
  • @DaniloPatrucco most likely the cmdlet accesses the rest api which requires a uuid instead of an id. I have corrected my answer – rinat gadeev Feb 16 '23 at 08:10
  • thank you for the answer, it was a good hunch but it did not solve the issue. I did more research and this worked Stop-VM -VM "test_machine_vm_01_output" -confirm:$false . I am not sure why this worked vs the invoke-startpower or the invoke-getvmpower. – Danilo Patrucco Feb 16 '23 at 18:39
0

For anyone with the same problem, the solution was to use the following command:

Start-VM -VM $vmname -confirm:$false

The -config:$false is used just to avoid any typing.

Not sure why the other command does not work and why it does not pick up the VM, but using Start-VM and Stop-VM commands starts and stop the VM created.

Danilo Patrucco
  • 110
  • 3
  • 10