Hi,
the try catch block did not turn up anything ... I am posting the (almost) complete code, maybe somebody sees something:
from Deploy-VM.ps1:
if(!$global:DefaultVIServer) {
if(!(Get-PSSnapin | Where {$_.name -eq "vmware.vimautomation.core"}))
{
try
{
Add-PSSnapin VMware.VimAutomation.Core -ea 0| out-null
}
catch
{
throw "Could not load PowerCLI snapin"
}
}
try
{
Connect-VIServer $vcserver -session $session
}
catch
{
throw "Failed to connect to VI server"
}
}
$now = Get-Date
Write-Host "Staring deployment process: $now"
# find best datastore
Write-Host "Finding best Datastore ..."
$datastore = FindDatastoreForVM $clusterName $diskGB
if (!$datastore)
{
Write-Host "No datastore could be found. VD cannot be deployed! Aborting."
return
}
# fetch the OS customization spec
$custSpec = Get-OSCustomizationSpec $custSpecName -ErrorAction:Stop
if (!$custSpec)
{
Write-Host "Guest OS customization specification could not be found. Aborting."
return
}
Write-Host "Cloning VM ..."
try {
$vm = New-VM `
-Name $name `
-ResourcePool $clusterName `
-Location $folder `
-Datastore $datastore `
-Template $template `
-OSCustomizationSpec $custSpec `
-ErrorAction:Stop
}
catch
{
Write-Host "An error ocurred during template clone operation:"
# output all exception information
$_ | fl
Write-Host "Cleaning up ..."
# clean up and exit
$exists = Get-VM -Name $name -ErrorAction SilentlyContinue
If ($Exists){
Remove-VM -VM $exists -DeletePermanently
}
return
}
# make hardware adjustments
Write-Host "Changing virtual hardware configuration ..."
ChangeVMHardware $vm $numCPU $memoryGB $diskGB
# start VM and wait for it
Write-Host "Staring VM and waiting for Sysprep to complete ..."
$sysprep = StartVMAndWaitForSysprep $vm
if (!$sysprep)
{
Write-Host "Guest Customization failed.... Aborting."
$exists = Get-VM -Name $name -ErrorAction SilentlyContinue
If ($Exists){
Remove-VM -VM $exists -DeletePermanently
}
}
# wait until the vm shows on the network
Write-Host "Waiting for VMware Tools to report IP address ..."
$hasIp = $vm
$now = Get-Date
Write-Host "Deployment finished: $now"
return $vm
The functions used above (ChangeVMHardware, StartVMAndWaitForSysprep, WaitForToolsToReportIP) are not shown above, as they take a lot of space and I can't see why they should be causing the error I am seeing. But if you think they might, let me know and I'll post them, too.
Control Script:
$job = {
Set-Location $args[0]
.\Deploy-VD.ps1 -session $($args[1]) -vcserver $($args[2]) -name $($args[3]) -clusterName $($args[4]) -folder $($args[5]) -template $($args[6]) -custSpecName $($args[7]) -numCPU $($args[8]) -memoryGB $($args[9]) -diskGB $($args[10])
}
$currentPath = (Split-Path -parent $MyInvocation.MyCommand.Definition)
$session = $global:DefaultVIServer | %{ $_.sessionsecret }
$vcserver = $global:DefaultVIServer.ServiceUri.Host
Write-Host "CURRENTPATH = $currentPath"
Write-Host "SESSION = $session"
Write-Host "VCSERVER = $vcserver"
1..1 | foreach {
$id = "{0:D3}" -f $_
Start-Job -ScriptBlock $job -ArgumentList $currentPath, $session, $vcserver, "vd$id", 'cluster01', 'folder1', 'VMTPL', 'default', '2', '4', '50'
}
Get-Job | Wait-Job
Write-Host "Done!"
I put
try
{
}
catch
{
$Error[0].Exception | Format-List *
}
around all the code from Deploy-VM.ps1 I posted and did see anything I haven't already seen before.
cheers
Mathias