Highlighted
Enthusiast
Enthusiast

Add VM to inventory with PowerCLI

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

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

0 Kudos
6 Replies
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
Enthusiast
Enthusiast

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?

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
Enthusiast
Enthusiast

OK. Thanks for your help.

0 Kudos
Highlighted
Expert
Expert

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?

Highlighted
Enthusiast
Enthusiast

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

Thanks a lot!

0 Kudos