Quick and Dirty Scripting

A blog that focuses on automating system administration tasks for Linux, Windows, and VMware ESX

Tuesday, November 13, 2007

 

Creating a Virtual Machine with Powershell

Sorry for the delay in posting this week. I had out-of-town guests in all weekend so everything has been turned upside down. I would like to continue from last week and show how easy it is to create a new virtual machine with Powershell. Again you'll need the VMware Powershell management Snap-in before you have access to these commands.

To Create a Virtual Machine, you need to do the following:
1. Connect to your Virtual Center server -
2. Connect to the ESX Host where you want to create the VM -
3. Create the virtual machine -
4. If you want, you can specify options while you are creating the VM or you can use the Set-VM to modify the VM's specifications.

I tried to create a new VM from a template with the following steps, but I continually got an error while doing so. I guess this just goes to show that VMware is still developing this code and it has some ways to go.

1. Get all templates that VC knows about
2. Create new virtual machine from the first template
If someone could show me what I am doing wrong, that would be great.

Labels:


Comments:
$vc = Get-VIServer -Server "VCServer" -User Joe -Password Secret
$esx = Get-VMHost -Server $vc -Name "ESXHOST.NET"
$temp = Get-Template -Server $vc |where {$_.Name -like "*xp1"}
$vm = New-VM -Host $esx -Template $temp -Name "New Virtual Machine"

This Job starts but stops after a few seconds with "Unable to communicate with the remote host, since it is disconnected."
 
Hi Brian

I would also like to start playing with the Windows Powershell. Would you know where I can get the VMware CommandLets?

Gabrie
 
You can get the VMware Powershell Snap-in by emailing VI_TK_4Win-Admin@vmware.com and requesting to be a part of their beta program.
 
We'll take a look at what you're running into, Brian. Maybe if you can send some of the details to our tech preview email address, we can follow up directly.

A few notes on Eric's comment:
1. assuming you're working with a single server (which appears to be the case here), you can simplify a bit by leaving out the "-server $vc" parameter after you've established the connection.
2. You should be able to do $temp = Get-Template -Name "*xp1" (though it should of course work as in Eric's comment as well). If you run into any trouble there, please let us know through the tech preview feedback.
3. it's possible to have hosts in the VC inventory that are disconnected, in which case we can't create the VM. Is that the case here? If not, please follow up with us through the tech preview feedback as we'd like to work through the issue with you.

And gabrie, here's some information on registering for the tech preview: http://blogs.vmware.com/vipowershell/2007/10/early-access-te.html
 
Hi Antonio,

I discovered that my template was orphaned, after I created a new template everything runs fine.
Keep up the good work,

Eric Sloof
 
Hi,

I'm successful in creating a VM from the template. But how do i clone a vm to a different datastore from the template.

what is the format of the string to be typed in -diskpath option.

any help is appreciated.
 
Did you ever get the format to follow the -diskapth arg with the new-vm cmdlet?
 
Post a Comment





<< Home

Archives

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]