There are others, but I think this method rules. I'll first list the entire one-liner then break it down by color code:
Get-View -ViewType VIrtualMachine -Property Name , SnapShot, LayoutEx -Filter @{"Snapshot.CurrentSnapshot" = "snapshot" } | ? { $_.name -match "$VM" } |
Select @{"N"="VM" ; E={$_.Name}},
@{N= "vCenter" ; E= { $_.Client.ServiceUrl.Split("/")[2].split(":")[0] }},
@{N= "Snapshots" ; E = { (($_.LayoutEx.Snapshot | % { $_.Key }) | measure).count } },
@{N= "SnapsSizeGB" ; E = { (($_.LayoutEx.File | ? { $_.Type -match "snapshotdata" } | measure -Property size -Sum ).sum *3 / 1gb ).ToString("#,0.00") } } ,
@{N= "OldestSnapshot" ; E = { $_.Snapshot.RootSnapshotList | sort createtime | select -F 1 createtime | % { $_.CreateTime } } },
@{N= "DaysOld" ; E = { $_.Snapshot.RootSnapshotList | sort createtime | select -F 1 createtime | % { ((Get-Date) - $_.CreateTime ).Days } } } | sort -desc DaysOLD
The first statement:
Get-View -ViewType VIrtualMachine -Property Name , SnapShot, LayoutEx -Filter @{"Snapshot.CurrentSnapshot" = "snapshot" }
The above line will simply return all VM's with Snapshots. It's that simple, and it's very fast. Next the results are piped to a Where filter.
Notice the "$VM" variable? Use it to filter your script by VM names, and remember this that field is a regular expression, so you can't use the typical wild card (* or ?) characters. Normally, the -Filter array would contain "Name"="$VM", but doing that here would present an "OR" filter statement which would return wrong results. So we filter on found items in Get-View.
? { $_.name -match "$VM" }
The final statement is a Select statement massages the results into these kind of results:
VM
|
vCenter
|
Snapshots
|
SnapsSizeGB
|
OldestSnapshot
|
DaysOld
|
Windows2003r2_Std_Tpl | vc2wrvc06.int.loc | 2 |
0.00
| 20/28/2022 2:56:22 PM | 527 |
2622PPPHMR3 | vc2wrvc03.int.loc | 2 | 22.00 | 6/22/2022 3:59:26 PM | 290 |
2622PPPH2 | vc2wrvc03.int.loc | 2 | 72.00 | 7/28/2022 7:33:36 PM | 263 |
2650ppph2 | vc2wrvc03.int.loc | 2 | 72.00 | 7/28/2022 7:35:02 PM | 263 |
2572ppph2 | vc2wrvc02.int.loc | 2 | 72.00 | 7/28/2022 7:32:25 PM | 263 |
ar2550ppph2 | vc2wrvc02.int.loc | 2 | 72.00 | 7/28/2022 2:32:40 PM | 263 |
2568xptest2 | vc2wrvc04.int.loc | 2 | 6.05 | 2/6/2023 20:38:56 PM | 60 |
2568XPTEST3 | vc2wrvc04.int.loc | 2 | 24.20 | 2/23/2023 5:24:22 PM | 53 |
2568XPTEST4 | vc2wrvc04.int.loc | 2 | 22.05 | 2/23/2023 5:24:06 PM | 53 |
0223CTXWEB02 | vc2wrvc03.int.loc | 2 | 22.05 | 2/28/2023 20:55:03 PM | 48 |
0223CTXWEB02 | vc2wrvc03.int.loc | 3 | 36.25 | 2/20/2023 9:53:43 PM | 46 |
0223CTXSQL02 | vc2wrvc03.int.loc | 2 | 22.05 | 2/22/2023 9:56:39 PM | 44 |
2568CTXWEB04 | vc2wrvc04.int.loc | 2 | 0.00 | 2/26/2023 7:56:02 PM | 40 |
2706AMRSCN21 | vc2wrvc04.int.loc | 2 | 9.05 | 3/26/2023 7:00:54 PM | 22 |
2568AMRDBE02 | vc2wrvc04.int.loc | 0 | 0.00 | 4/4/2023 22:08:25 AM | 4 |
One problem I find is the snapshot size. The Get-View VirtualMachine object returns LayoutEx.File objects, but these objects do not report the same size disk as the Get-Snapshot returns.
However, when I visually inspect the actual snapshot disk on the VMFS volume, I find that LayoutEx.File size is accurate and the Get-Snapshot is incorrect. If I'm missing something, let me know.
ReplyDeleteWhat an awesome post, I just read it from start to end. Learned something new after a long time.
Manual testing training in Chennai
Selenium testing training in Chennai
Well written article and the topic that you have selected is too good. You are a blessed person and the way you executed the theme is highly appreciable
ReplyDeleteSelenium Training in Chennai
Big data analytics training
ReplyDeleteMBA in event management
MBA in marketing management
learn core java online
online aptitude training
I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .
ReplyDeleteangularjs Training in bangalore
angularjs Training in bangalore
angularjs interview questions and answers
angularjs Training in marathahalli
angularjs interview questions and answers
angularjs-Training in pune
All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
ReplyDeleteJava training in Pune
Java interview questions and answers
Java training in Chennai | Java training institute in Chennai | Java course in Chennai
Java training in Bangalore | Java training institute in Bangalore | Java course in Bangalore
Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
ReplyDeleteaws training in bangalore | best aws training in bangalore
thanks to sharing this information
ReplyDeletedata science training in bangalore
data science classroom training in bangalore
best training institute for data science in bangalore
best data science training institute in bangalore
data science with python training in bangalore
best data science training in bangalore
UiPath Training in Bangalore
best tableau training institutes in bangalore
I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject
ReplyDeleteVirtual Machines & Scale-Sets |App Services|
Cloud Services | Azure Active Director
I Got Job in my dream company with decent 12 Lacks Per Annum Salary, I have learned this world most demanding course out there in the current IT Market from the Data Science Training in Pune Providers who helped me a lot to achieve my dreams comes true. Really worth trying.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteYour good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeletePython Certification Course
Digital Marketing Certification Course
AWS Certification Course
Selenium Online Course
Data Science Certification Course
DevOps Certification Course
Informative blog.It is superb article.
ReplyDeleteJava training in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Online Training
yurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
İE473
Hollanda yurtdışı kargo
ReplyDeleteİrlanda yurtdışı kargo
İspanya yurtdışı kargo
İtalya yurtdışı kargo
Letonya yurtdışı kargo
P12
Litvanya yurtdışı kargo
ReplyDeleteLüksemburg yurtdışı kargo
Macaristan yurtdışı kargo
Malta yurtdışı kargo
Polonya yurtdışı kargo
ER5VK
Portekiz yurtdışı kargo
ReplyDeleteRomanya yurtdışı kargo
Slovakya yurtdışı kargo
Slovenya yurtdışı kargo
İngiltere yurtdışı kargo
NDYUO6
Yunanistan yurtdışı kargo
ReplyDeleteAfganistan yurtdışı kargo
Amerika Birleşik Devletleri yurtdışı kargo
Amerika Samoası yurtdışı kargo
Angola yurtdışı kargo
FNYWJ