VMware Cloud Community
Vandalay
Enthusiast
Enthusiast

Works here but not there

I've got a lab put together with three different Sites A, B, and C.  Each has it's own vCenter (working on an SRM project).

I put together a script that SnapShot's a VM in site B, but keep running into an error.  Thing is, it works in site A and site C just fine.  And, it works when run in the PowerGui Script Editor for Site B! But, when I run it in PowerCLI, I get this error:

New-Snapshot : 10/19/2011 1:18:30 AM    New-Snapshot        An item with the same key has already been added.
At C:\SRMScripts\VMClone.ps1:31 char:27
+     $clonesnap = New-Snapshot <<<<  -Name "DO NOT DELETE - Clone Snapshot" -VM $vm
    + CategoryInfo          : NotSpecified: (:) [New-Snapshot], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewSnapshot

The other odd thing is that even when it throws this error, vCenter still takes the SnapShot of the VM with no error in vCenter.  But because the command doesn't return a SnapShot object, the subsequent steps fail.

Here's the code up until the point where the error occurs.  Help is appreciated:

param (
[parameter(Mandatory=$true)][string]$SourceName,
[parameter(Mandatory=$true)][string]$vcRecoveryServer,
[parameter(Mandatory=$true)][string]$testNetwork
)
connect-viserver $vcRecoveryServer

$vm = Get-VM $SourceName

$clonesnap = $null

# Create new snapshot for clone
try{
$clonesnap = New-Snapshot -Name "DO NOT DELETE - Clone Snapshot" -VM $vm
} catch {
#Most of the time when this fails, the SnapShot was still created, lets see if it's there
Start-Sleep -Seconds 120
$clonesnap = Get-Snapshot -Name "DO NOT DELETE - Clone Snapshot" -VM $vm -ErrorAction:SilentlyContinue
} finally {
if($clonesnap -eq $null){throw "Failed creating SnapShot."}
}

0 Kudos
4 Replies
Vandalay
Enthusiast
Enthusiast

Anyone else seen behavior like this?

0 Kudos
Zsoldier
Expert
Expert

Are the PowerCLI scripts being run from different versions of PowerCLI?  Where are the scripts being run from?

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
LucD
Leadership
Leadership

Does the datastore in site B, where the VM is located, have multiple extents ?

The fact that you don't see the error in PowerGui for Site B could be due to the error handling.

Can you for example try to run the script from the PowerShell ISE or the PowerSE editor instead ?


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

0 Kudos
Vandalay
Enthusiast
Enthusiast

The scripts ran fine from the actual SRM server (different than I was using before) against all sites.  So, chalking it up to the IT gremlins and moving on.

0 Kudos