Renaming a Snapshot

Jan 19, 2009 at 1:55 PM
Is there any way to rename a snapshot, either during creation, or after?

Jan 19, 2009 at 8:47 PM
I have been able to figure this one out. Here is the new function I have written.

Filter Rename-VMSnapshot
{Param( $snapshot, $vmname, $newname )
 if ($snapshot -eq $null) {$snapshot=$_ }
 if ($snapshot -is [Array]) {$snapshot | ForEach-Object {Remove-VMSnapshot -snapshot $snapshot -vmname $vmname -newname $newname} }
 if ($snapshot -is [System.Management.ManagementObject]) {
     $VSMgtSvc=Get-WmiObject -ComputerName $snapshot.__server -NameSpace  "root\virtualization" -Class "MsVM_virtualSystemManagementService"
     Get-VM $vmname | Out-Null
     $VM = gwmi -namespace root\virtualization Msvm_ComputerSystem | where {$_.ElementName -eq $vmname}
     $snapshot.ElementName = $newname
     ## Commit changes
     $result=$VSMgtSvc.ModifyVirtualSystem($VM.__PATH, $snapshot.psbase.getText(1))
     if ( $result.ReturnValue -eq 0 )
        { "Renamed snapshot" }
        {Write-Error "Could not rename snapshot"} }
#Example 1: get-vmsnapshot $Core | where {$_.CreationTime -gt 20090119} | rename-vmsnapshot -vmname $Core -newname $newSnapshotName

Jan 26, 2009 at 5:16 PM
I wrote a rename-snapshot  as part of the work to do  update-snapshot  - both of which are in the new 1.0 release.