0

What is the canonical way to use VMware's ovftool to query to see if a VM exists or not?

If I run this command:

ovftool vi://username@password@myvsphere/mydatacenter/vm/myvm

I might get this response:

Error: Got fault from server: The attempted operation cannot be
performed in the current state (Powered on).
Error: Fault cause: vim.fault.InvalidState

I know I can do the following and then look for "Locator does not refer to an object" but is there a different command or (set of) option(s) I can run that will return a simple true or false or something else concise that does not indicate an error?

ovftool vi://username@password@myvsphere/mydatacenter/vm/avmthatisnothere

Just FYI the above returns this:

Error: Locator does not refer to an object:
vi://username@password@myvsphere/mydatacenter/vm/avmthatisnothere
0

You're using the wrong tool. You cannot serve beer with a fork.

VMware OVF Tool is a command-line utility that allows you to import and export OVF packages to and from many VMware products.

To check whether a VM with the name myVM exists you should try PowerCLI:

Get-VM -Name myVM

https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/get-vm/#Default

1
  • Seems strange that a tool that can power-on and power-off a VM is not the right tool to determine if a VMs actually exist to power on or off. That said, it seems like a huge amount of effort to use the "right" tool just to test for existence when by side-effect I can use ovftool in a much lighter weight manner to check the same thing. Oct 9 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.