?
Solved

PowerShell Script to create a Customized VMware VM

Posted on 2012-03-12
9
Medium Priority
?
1,483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 123

Accepted Solution

by:
Andrew Hancock (VMware vExpert / EE MVE^2) earned 2000 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 123
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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 123
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 123
ID: 38842796
2. Accept http:#a37714243
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Teach the user how to install log collectors and how to configure ESXi 5.5 for remote logging Open console session and mount vCenter Server installer: Install vSphere Core Dump Collector: Install vSphere Syslog Collector: Open vSphere Client: Config…
Advanced tutorial on how to run the esxtop command to capture a batch file in csv format in order to export the file and use it for performance analysis. He demonstrates how to download the file using a vSphere web client (or vSphere client) and exp…
Suggested Courses

770 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