Solved

PowerShell Script to create a Customized VMware VM

Posted on 2012-03-12
9
1,375 Views
Last Modified: 2013-02-09
Hi experts,
I got the following Powershell script from this link:

http://communities.vmware.com/message/1753790
 
 
 
Somehow I’ve been trying to run the script, but it does not work, I connect via PowerCLI to my vCenter, I exported to a csv file the configuration that I am trying to accomplished, but when trying to run the script (below) I am getting the errors

$worksheet = Import-CSV "C:\Export-Files\Windows2k8-Template.csv"
$worksheet | ForEach-Object {
      new-VM `
          -Name $_.VM_Name `
          -VMHost $_.Host `
          -Template $_.Template `
          -Datastore $_.Datastore `
          -OSCustomizationspec $_.Customization `
          -Location $_.Location `
          -DiskStorageFormat $_.DiskStorageFormat |`
          Set-VM -NumCpu $_.CPU -MemoryMB $_.Memory -Confirm:$false
          Start-VM -VM $_.VM_Name
         }

Errors that I am getting:
New-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\Users\jluciano\AppData\Local\Temp\2bfdd9bc-e8b6-47f3-b692-eeae9d50f64a.ps1:4 char:16
+           -Name <<<<  $_.VM_Name `
    + CategoryInfo          : InvalidData: (:) [New-VM], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
 
Start-VM : Cannot validate argument on parameter 'VM'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\Users\jluciano\AppData\Local\Temp\2bfdd9bc-e8b6-47f3-b692-eeae9d50f64a.ps1:12 char:23
+           Start-VM -VM <<<<  $_.VM_Name
    + CategoryInfo          : InvalidData: (:) [Start-VM], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.StartVM

My final goal is to get this information on a csv or xml file, that I can deploy based on this info:

Name
Description
NumCpu
MemoryMB
HardDisk1 Size (GB)
HardDisk1 Datastore
HardDisk2 Size (GB)
HardDisk2 Datastore
HardDisk3 Size (GB)
HardDisk3 Datastore
VMSwapfilePolicy
Swap Datastore
PortGroup1 Name
PortGroup1 VLAN
PortGroup2 Name
PortGroup2 VLAN
PortGroup3 Name
PortGroup3 VLAN
Folder
ResourcePool

Of course if I somebody assist me with the script
0
Comment
Question by:Islandr
  • 4
  • 3
9 Comments
 
LVL 119

Accepted Solution

by:
Andrew Hancock (VMware vExpert / EE MVE^2) earned 500 total points
ID: 37714243
It looks as if one, or more, of the Names in your CSV file does not find a VM.

As a consequence the variable $_.VM_Name  will be $null and all the following cmdlets will fail.

This is because of the following

Make sure the header of your CSV has the value Name, and change  $_.VM_Name to $_.Name in the script above.

This will cure the issue of the script not running. Make sure you have a Template and Guest Customization as well for the script to run correctly.

This script will deploy/clone a VM based on the Template and Guest Customization name, using the memory and cpu parameters supplied. Note the Memory is in MB! Not GB!
0
 

Author Comment

by:Islandr
ID: 37720296
Hanccoka,

I tried that and did not work, I've been hitting my head against the wall and nothing is really works, my main goal is to get the following info into a xml file:

Name
Description
NumCpu
MemoryMB
HardDisk1 Size (GB)
HardDisk1 Datastore
HardDisk2 Size (GB)
HardDisk2 Datastore
HardDisk3 Size (GB)
HardDisk3 Datastore
VMSwapfilePolicy
Swap Datastore
PortGroup1 Name
PortGroup1 VLAN
PortGroup2 Name
PortGroup2 VLAN
PortGroup3 Name
PortGroup3 VLAN
Folder
ResourcePool


And then build a template where I can deploy a VM based on the information collected from the XML template.  Please let me know if further information is needed.

Thanks,
0
 
LVL 119
ID: 37720321
post your CSV, it works fine for me.

do you have

1. A Template created
2. Guest Customization created.

What's the error message.

Post the script you are using.
0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 

Author Comment

by:Islandr
ID: 38062892
Hanccoka,

At the end we endup not using the script, but I'll pick your brain some other time thanks.
0
 

Author Comment

by:Islandr
ID: 38839334
I've requested that this question be deleted for the following reason:

I am very disappointed with this service, I post a question and I have to give up on it, because nobody bother to replied
0
 
LVL 119
ID: 38839335
I am very disappointed with this service, I post a question and I have to give up on it, because nobody bother to replied

I answered your question, and I took the time to test the script and create a CSV file. It tested fine for me. I asked you to post the actual script you were using, and you replied

At the end we endup not using the script

It seems like it was me as a volunteer, that has wasted my time here on replying to this question.
0
 
LVL 119
ID: 38842796
2. Accept http:#a37714243
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If we need to check who deleted a Virtual Machine from our vCenter. Looking this task in logs can be painful and spend lot of time, so the best way to check this is in the vCenter DB. Just connect to vCenter DB(default DB should be VCDB and using…
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Teach the user how to convert virtaul disk file formats and how to rename virtual machine files on datastores. Open vSphere Web Client: Review VM disk settings: Migrate VM to new datastore with a thick provisioned (lazy zeroed) disk format: Rename a…
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question