VMware Cloud Community
TICTOC201110141
Enthusiast
Enthusiast

VM Deploy Issue

Using Mike Foley's How to provision 500 VM’s. Fast. »  I keep getting the following error. I am using 5.1 PowerCLI SDK

Name                           Port  User
----                           ----  ----
0.0.0.0                        443   STORK
Collecting Template lists
Collecting Datastore lists
Collecting Host lists
Collecting number of VMs per host
Collecting number of VMs per datastore
Finding host with least amount of tv-test VMs on it
Finding datastore with least amount of tv-test VMs on it
Create a virtual machine called tv-testjwten0 on cec-esxi03.cxo.storage.lr.net using a template called  onto a datastore called
Get-Datastore : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and the
try the command again.

At C:\scripts\vmdeploy.ps1:66 char:119
+     $taskTab[(New-VM -Name $VM_Name -Template $template -VMHost (Get-VMhost $LeastHost.Name) -Datastore (Get-Datastore <<<<  $LeastDatastore.Na
-DiskStorageFormat Thin -RunAsync ).Id] = $VM_Name
    + CategoryInfo          : InvalidData: (:) [Get-Datastore], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

Property 'NumVM' cannot be found on this object; make sure it exists and is settable.
At C:\scripts\vmdeploy.ps1:67 char:72
+     $DSVMs | Where { $_.Name -eq $LeastDatastore.Name } | Foreach { $_. <<<< NumVM++ }
    + CategoryInfo          : InvalidOperation: (NumVM:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

-----------------------
VM Deployment completed
-----------------------
-----------------------
Starting VM's
-----------------------


script is from 2010 and I am using 5.1 and 5.5 ESXI / PowerCLI SDK's


#------------------------------------------------------------------------------
# 1st draft written by Mike Foley, @mikefoley, Virtualization Evangelist, RSA, The Security Division of EMC
# Contributions from Alan Renouf, @alanrenouf, EMC vSpecialist and PowerCLI guru
# Many thanks to those who's code we used, especially Luc Dekens, @LucD
#------------------------------------------------------------------------------
# All information, statements, and descriptions herein are offered AS IS
# only and are provided for informational purposes only. EMC Corporation
# does not guarantee the performance of, or offer a warranty of any kind,
# whether express, implied, or statutory, regarding the information herein
# or the compatibility of the information herein with EMC Corporation software
# or hardware products or other products.
#------------------------------------------------------------------------------
# 06-Apr-2010, Mike Foley, A simple Powershell/PowerCLI script to create a bunch of VM's. Written from lots of examples
# 20-Apr-2010, Alan Renouf, applied a different method of working out the numbers and re-wrote some of the code
# 21-Apr-2010, Alan Renouf, Fixed datastores which are used for deployment as per email from Mike.
#------------------------------------------------------------------------------
# You'll need to have the PowerCLI cmdlets installed. Get these from VMware.
# http://www.vmware.com/go/powercli

Add-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue
#
#Things you can change
#------------------------------
$vchost = "00.00.00.00"
$num_vms_total = 1
$vm_prefix = "tv-test"
$Template_prefix = "00-Template"
#-------------------------------
#Don't change below
$Template_Name = $vm_prefix + "*"

Connect-VIserver $vchost -user FAKE -password FAKE

Write-Host "Collecting Template lists"
$Template_List = Get-Template $Template_Name | Select Name, @{N="Datastore";E={Get-VIObjectByVIView (Get-View ($_).DatastoreIdList)}} | Sort Name, Datastore

Write-Host "Collecting Datastore lists"
$Datastore_list = $Template_List | Select -Expand Datastore

Write-Host "Collecting Host lists"
$hosts = Get-VMHost | Sort Name

Write-Host "Collecting number of VMs per host"
$HostVMs = $hosts | Select Name, @{N="NumVM";E={@(($_ | Get-Vm ($vm_prefix + "*"))).Count}} | Sort NumVM, Name

Write-Host "Collecting number of VMs per datastore"
$DSVMs = $Datastore_list | Select name, @{N="NumVM";E={@($_ | Get-VM ($vm_prefix + "*")).Count}} | Sort NumVM, Name

#Setup for Get-Random in the loop below
$min = [char]'a'
$max = [char]'z'
$alpha = [char[]]($min..$max)
$ofs = ''
$taskTab = @{}
$vm_count = 0

While ($vm_count -lt $num_vms_total){
    Write-Host "Finding host with least amount of $vm_prefix VMs on it"
    $LeastHost = $HostVMs | Sort NumVM | Select -First 1
    Write-Host "Finding datastore with least amount of $vm_prefix VMs on it"
    $LeastDatastore = $DSVMs | Sort NumVM | Select -First 1
    $ran_text = [string]( $alpha | Get-Random -Count 5 )
    $VM_Name = $vm_prefix + $ran_text + $vm_count
    $Template = ($Template_List | Where {$_.Datastore.Name -eq $LeastDatastore.Name}).Name
    Write "Create a virtual machine called $VM_Name on $($LeastHost.Name) using a template called $Template onto a datastore called $($LeastDatastore.Name)"
    $taskTab[(New-VM -Name $VM_Name -Template $template -VMHost (Get-VMhost $LeastHost.Name) -Datastore (Get-Datastore $LeastDatastore.Name) -DiskStorageFormat Thin -RunAsync ).Id] = $VM_Name
    $DSVMs | Where { $_.Name -eq $LeastDatastore.Name } | Foreach { $_.NumVM++ }
    $HostVMs | Where { $_.Name -eq $LeastHost.Name } | Foreach { $_.NumVM++ }
    $vm_count ++
}

Write-Host "-----------------------"
Write-Host "VM Deployment completed"
Write-Host "-----------------------"

Write-Host "-----------------------"
Write-Host "Starting VM's"
Write-Host "-----------------------"


#
## Start each VM that is completed
$runningTasks = $taskTab.Count
while($runningTasks -gt 0){
    Get-Task | % {
        if($taskTab.ContainsKey($_.Id) -and $_.State -eq "Success"){
            $xx = Get-VM $taskTab[$_.Id]
           Write-Host "Starting VM " $xx.Name
            Get-VM $taskTab[$_.Id] | Start-VM
            $taskTab.Remove($_.Id)
            $runningTasks--
        }
        elseif($taskTab.ContainsKey($_.Id) -and $_.State -eq "Error"){
            $taskTab.Remove($_.Id)
            $runningTasks--
        }
    }
    Start-Sleep -Seconds 15
}

#
#Disconnect-VIserver -server $vchost -confirm:$false
#
#
#
#foreach($Name in $newVmList){
#    $taskTab[(New-VM -VM (Get-VM $modelVm) -Name $Name -VMHost (Get-VMHost -Name $esxName) -RunAsync).Id] = $Name
#}


0 Kudos
7 Replies
LucD
Leadership
Leadership

It seems the script isn't able to determine the datastore to use.

Note that Mike's script checks for Templates that have a name that starts with "00-Template".

Do you have such templates in your environment ?

The script then take the datastores on which these templates are located, and looks for the datastore that has the least number of the VMs on it.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
TICTOC201110141
Enthusiast
Enthusiast

Yes I have the Full template name in just redacted it from the post.

$Template_prefix = "00-rhel-workstation65-64bit-146GB-Template"

it's there and I use it daily so I am not sure why this is happening. I thought maybe it was due to changes in PowerCLI between 2010 and the latest 5.5.

Good catch though!

0 Kudos
LucD
Leadership
Leadership

The script displays some info which seems to indicate the template is not found (the name is missing from the line).

Create a virtual machine called tv-testjwten0 on cec-esxi03.cxo.storage.lr.net using a template called  onto a datastore called


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
TICTOC201110141
Enthusiast
Enthusiast

Thought of that so I created a single ESXI server setup with one datastore and one VM template mimicking our Prod systems. Then tried it using VM Workstation 9.0 setup.

Got the same error Smiley Sad

So what would I need to do to Hard Code the datastore name in? It's just another thought to see if the rest actually works.

0 Kudos
LucD
Leadership
Leadership

Try replacing this line

$Datastore_list = $Template_List | Select -Expand Datastore

with

$Datastore_list = Get-Datastore

But that will not solve the missing Template, or you could hardcode that one.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
TICTOC201110141
Enthusiast
Enthusiast

I hard coded the datastore but the template hard code is still failing...

0 Kudos
LucD
Leadership
Leadership

How did you hardcode the template, and which errors do you get ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos