VMware Cloud Community
ronaldoalv
Contributor
Contributor

change in snapshot ID

hi all, I use a snapshot to clone a VMs. sometimes I get an error that the snapshot is not exist. when I check it, I found that the ID are changed!, why is it? how I can avoid this change? thanks a lot

Tags (1)
Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

Could you perhaps give us some more info ?

Which code did you use ?

What is the error message ?


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

New-VM -VM $VM -LinkedClone -ReferenceSnapshot $SnapShot -ResourcePool $Location -Datastore $datastore -Name $name -VApp $vApp this is the command to create vm. the error is that the snapshot are not found. It's not found because the ID has changed. There is a reason that the ID has changed?

Reply
0 Kudos
LucD
Leadership
Leadership

It would be helpful if you could include a bit more code.

How is the content of the $Snapshot variable obtained ?

And what is the exact error message, perhaps a screenshot ?


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

I handle it with try and catch so I dont get the exact error message. I handle only 'Core_OutputHelper_WriteNotFoundError' error for snapshot. and it's happend when I use "Get-Snapshot -VM $VM -Id $snapshotID" so the error are not come from the creation command

Reply
0 Kudos
LucD
Leadership
Leadership

If you don't want to share/show the code, it will be difficult to diagnose the problem I'm afraid.


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

Reply
0 Kudos
ronaldoalv
Contributor
Contributor

this is the place that I get the error:

try{

     $SnapShot = Get-Snapshot -VM $VMSnapShot -Id $template.snapshot

}

catch{

     $exp=$_.Exception

     if($exp.ErrorId -eq 'Core_OutputHelper_WriteNotFoundError')

            if($exp.Message.Contains('snapshot')){

                     $msg="--requestId $requestID --operation deploy --status failure --cause snapshot_not_found" } } else{ $msg="--requestId $requestID --                                   operation deploy --status failure --cause vm_or_snapshot_fail"

               }

      SendMessage $msg

      exit 1

}

this is how I create the snapshot:

$snapshot = New-Snapshot -VM $VM -Name $name

when I got the error I check manualy (get-snapshot -vm $vm | %{write-host $_.id}) and found that it's change

Reply
0 Kudos
LucD
Leadership
Leadership

How do you get the snapshotID in $template.snapshot ?

I would suggest running through your code with a debugger, from the New-Snapshot till the moment you do the Get-Snapshot.

Snapshot IDs do not change, so there must be another cause for the ID change you see.

For a list of reasons why an ID can change, see William's When Do vSphere MoRef’s Change?


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

Reply
0 Kudos