VMware Cloud Community
scotty_p
Enthusiast
Enthusiast
Jump to solution

Add VM to inventory with PowerCLI

Can anyone tell me how I can just add 1 VM to inventory in vCenter?

I found a bunch of big scripts, but they just seem excessive.

Thanks,

Scott

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Do you mean creating a new VM ?

That can be done with the New-VM cmdlet.

Or do you mean registering a VM from the .vmx file ?

My Raiders of the Lost VMX post has a script for that.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Do you mean creating a new VM ?

That can be done with the New-VM cmdlet.

Or do you mean registering a VM from the .vmx file ?

My Raiders of the Lost VMX post has a script for that.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
scotty_p
Enthusiast
Enthusiast
Jump to solution

I do mean registering a VM with the .vmx file.

Thanks that's an impressive script. But is there an easy way to do this for just 1 VM and point to the location of the vmx file?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not that I know of.

The only method I know is the RegisterVM_Task (which is used in the script)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
scotty_p
Enthusiast
Enthusiast
Jump to solution

OK. Thanks for your help.

Reply
0 Kudos
mattboren
Expert
Expert
Jump to solution

Hey, guys-

There _is_ another way.  There is a "RegisterVM" ParameterSet on the New-VM cmdlet that allows for registering VMs via their .vmx file.  Specifically, the "-VMFilePath" parameter allows you to register a VM by specifying a datastore path to a valid .vmx file.  So, something like:

## add VM to inventory on given random host in given folder
New-VM -VMFilePath "[datastore0] myVM01/myVM01.vmx" -VMHost (Get-Cluster MyCluster | Get-VMHost | Get-Random) -Location (Get-Folder MyFolder) -RunAsync

I have not been able to pinpoint just when that parameter was added to the New-VM cmdlet, but from what I can tell, it was within the last few releases -- looks like it was there in PowerCLI v4.0u1.  Could not find much (anything) about it in the release notes, though.

We posted about it over at vNugglets a bit ago:  http://vnugglets.com/2011/01/re-registering-vms-removed-from.html.  It definitely comes in handy now and again.

How does that do for you, scotty p?

scotty_p
Enthusiast
Enthusiast
Jump to solution

This is great!!! Excactly what I was looking for.

Thanks a lot!

Reply
0 Kudos
extrCurious
Contributor
Contributor
Jump to solution

Hi,
is it possible to read a *.VMX file and determine if the VM is linux? then add the VM to inventory on linux-cluster?

KR
extremely curious

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not really.
You can specify whatever you want for GuestId.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos