powershellvmwarevspherevcenter

Vsphere Invoke-StartVMPower return error - Get-VM return VM info


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


Solution

  • 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.