VMware Cloud Community
usndk2
Contributor
Contributor
Jump to solution

How to list all VMs in a cluster along with number of snapshots and space consumed by the snapshot?

Hi All,

I not new to using powerCLI but this is my first script. I'm trying to create a  script to list the following so I can put it in a report:

  • VM Name and cluster
  • snapshot number
  • age of snapshot
  • storage consumed by the snapshot

Below is what I've come up with so far I get some of the info but no all and in the format I would like. Can some on please tell me where I'm going wrong?

$creds = Get-VICredentialStoreItem -file “C:\Scripts\vclogin.xml”

Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password

Get-Cluster| Get-VM | Get-Snapshot | Where-Object {$_. Created -lt (Get-Date). AddDays(-0)} |

Select-Object -Property @{Name=’Cluster’;Expression={$_.VMHost.Parent}}, VM, Name, @{N="Size";E={"{0:N2} GB" -f ($_.SizeGB)}}, Created | Format-Table

Keep its simple and go Virtual with VMware!
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster| Get-VM | Get-Snapshot |

Where-Object {$_. Created -lt (Get-Date). AddDays(-7)} | 

Select-Object -Property @{Name=’Cluster’;Expression={$_.VM.VMHost.Parent.Name}},

    VM, Name,

    @{N="Size";E={"{0:N2} GB" -f ($_.SizeGB)}},

    @{N='Days Old';E={[math]::Round((New-TimeSpan -Start $_.Created -End (Get-Date)).TotalDays,0)}} |

Format-Table  


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

View solution in original post

10 Replies
LucD
Leadership
Leadership
Jump to solution

Not sure exactly what you want.

Perhaps you can show what you currently get as output, and what you would like to get in the output ?


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

0 Kudos
usndk2
Contributor
Contributor
Jump to solution

Thanks for the reply! I've attached what I'm getting for an output. What I'm looking to get is a report that shows the following:

VM name, Cluster, the number of snapshots, age in days of the snap shot and the storage consumed by the snapshot. My output is Cluster without data, VM name, size in Gb which is fine because the snap shot is small (lab testing) and the date created. From what I have gotten so far, I think I just need to figure out how to convert the Created property into a calculation but I don't think I can  and get data from the Cluster Property.

Keep its simple and go Virtual with VMware!
0 Kudos
usndk2
Contributor
Contributor
Jump to solution

May I ask where can I get your vSphere Performance Reporting with PowerCLI: Automating vSphere Performance Reports book? Its not available anywhere.

Keep its simple and go Virtual with VMware!
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That book has been canceled


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster| Get-VM | Get-Snapshot |

Where-Object {$_. Created -lt (Get-Date). AddDays(-7)} | 

Select-Object -Property @{Name=’Cluster’;Expression={$_.VM.VMHost.Parent.Name}},

    VM, Name,

    @{N="Size";E={"{0:N2} GB" -f ($_.SizeGB)}},

    @{N='Days Old';E={[math]::Round((New-TimeSpan -Start $_.Created -End (Get-Date)).TotalDays,0)}} |

Format-Table  


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

usndk2
Contributor
Contributor
Jump to solution

Thanks it works great! I

Keep its simple and go Virtual with VMware!
0 Kudos
usndk2
Contributor
Contributor
Jump to solution

Oh sorry to hear that I was looking forward to reading it. I do have the PowerCLI Cookbook that helped me get as far as I did.

Keep its simple and go Virtual with VMware!
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Well, it's still on my personal list.

One day it will be there :smileygrin:


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

0 Kudos
vmCalgary
Enthusiast
Enthusiast
Jump to solution

LucD,

I like the code you shared for Cluster | VM | Snapshot way back ion Jan 28, 2016 10:10 PM in this post. I'm looking for a modification so that it's Datastore | VM | Snapshot. The resulting table would display:

Datastore Name     VM Name   Snapshot Name   Size   Days Old

I'm tripped up on the code.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean like this?

Get-Datastore -PipelineVariable ds | Get-VM | Get-Snapshot |

Where-Object {$_. Created -lt (Get-Date). AddDays(-7)} |

Select-Object -Property @{Name=’Datastore’;Expression={$ds.Name}},

    VM, Name,

    @{N="Size";E={"{0:N2} GB" -f ($_.SizeGB)}},

    @{N='Days Old';E={[math]::Round((New-TimeSpan -Start $_.Created -End (Get-Date)).TotalDays,0)}} |

Format-Table  


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

0 Kudos