VMware Cloud Community
thisischristia1
Contributor
Contributor
Jump to solution

Get-Snapshot | How to get File Path location of .vmsn in Datastore

How would i go about getting this? The -Property of this command doesn't contain a option or attribute for getting this?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Like this

Get-VM -PipelineVariable vm | Get-Snapshot -PipelineVariable snap |

select @{N='VM';E={$vm.Name}},Name,SizeMB,Created,

    @{N='VMSN';E={($vm.ExtensionData.Layout.Snapshot | where{$_.Key -eq $snap.ExtensionData.Snapshot}).SnapShotFile | where{$_ -match ".vmsn$"}}}


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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

$vmName = 'MyVM'

$snapName = 'MySnap'

$vm = Get-VM -Name $vmName

$snap = Get-Snapshot -VM $vm -Name $snapName

($vm.ExtensionData.Layout.Snapshot | where{$_.Key -eq $snap.ExtensionData.Snapshot}).SnapShotFile | where{$_ -match ".vmsn$"}


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

0 Kudos
thisischristia1
Contributor
Contributor
Jump to solution

How would I pull the VM and the Snapshot name automatically? So in others words. If I am connected to a vCenter, how would I pull all Snapshots with the file location. So in the below command how would i add the file location attribute? This command gets snapshots, I do not have to enter the snapshot name or VM name, once connected to the vCenter.

get-vm | get-snapshot | Select-Object -Property vm,created,sizeGB,name,description | Export-Csv -Path C:\Users\$env:username\Desktop\snapshots.csv

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM -PipelineVariable vm | Get-Snapshot -PipelineVariable snap |

select @{N='VM';E={$vm.Name}},Name,

    @{N='VMSN';E={($vm.ExtensionData.Layout.Snapshot | where{$_.Key -eq $snap.ExtensionData.Snapshot}).SnapShotFile | where{$_ -match ".vmsn$"}}}

 


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

0 Kudos
thisischristia1
Contributor
Contributor
Jump to solution

How would i also include the size, date and time of the file into your script?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Like this

Get-VM -PipelineVariable vm | Get-Snapshot -PipelineVariable snap |

select @{N='VM';E={$vm.Name}},Name,SizeMB,Created,

    @{N='VMSN';E={($vm.ExtensionData.Layout.Snapshot | where{$_.Key -eq $snap.ExtensionData.Snapshot}).SnapShotFile | where{$_ -match ".vmsn$"}}}


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

0 Kudos