Solved

PowerShell Script to create a Customized VMware VM

Posted on 2012-03-12
9
1,332 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 118

Accepted Solution

by:
Andrew Hancock (VMware vExpert / EE MVE) 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 118
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pass an array of strings between functions in a module | PowerShell 5 26
Powershell knowledge 2 19
unable to unmount datastore/ re-add host 7 20
virtualization 2 36
When converting a physical machine to a virtual machine using VMware vCenter Converter Standalone or vCenter Converter Enterprise, if an adapter type is not selected during the initial customization the resulting virtual machine may contain an IDE d…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Teach the user how to delpoy the vCenter Server Appliance and how to configure its network settings Deploy OVF: Open VM console and configure networking:
Teach the user how to rename, unmount, delete and upgrade VMFS datastores. Open vSphere Web Client: Rename VMFS and NFS datastores: Upgrade VMFS-3 volume to VMFS-5: Unmount VMFS datastore: Delete a VMFS datastore:

939 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now