List All VM’s with snapshots – “One-liner Wednesdays”

snapshot_find
Here is a quick way to list all of your virtual machines’ snapshots that are managed through the vCenter you are currently connected to.

get-vm | get-snapshot | select vm,powerstate | Out-GridView

snapshots_1liner01
I like using the “Out-GridView” cmdlet because it allows you to quickly filter the list. This is excellent when you want to sort specific types of vm’s. Example: “app”, “db”, “web” etc.


Reference:
VMware PowerCLI Documentation
Microsoft PowerShell Documentation

List HA reboots within the past 5 days – PowerCLI

    On 4.1

$Date = Get-Date
$HAVMrestartold =5
Get-VIEvent -maxsamples 100000 -Start ($Date).AddDays(-$HAVMrestartold) -type info | Where {$_.FullFormattedMessage -match "was restarted"} |select CreatedTime,FullFormattedMessage |sort CreatedTime -Descending

    On 5.x

$Date = Get-Date
$HAVMrestartold =5
Get-VIEvent -maxsamples 100000 -Start ($Date).AddDays(-$HAVMrestartold) -type warning | Where {$_.FullFormattedMessage -match "restarted"} |select CreatedTime,FullFormattedMessage |sort CreatedTime -Descending

Documenting VMware IP’s via PowerCLI – “One-liner quickies”

I am finishing up the new VMware lab at work and need to document the setup. Part of this documentation includes getting all the ip’s on each VMhost and their corresponding use. A quick and easy way to do this is to leverage the awesomeness of PowerCLI.

So, here is a great one-liner that requires little post formatting to get what you need:

Get-VMHostNetworkAdapter | select vmhost,portgroupname,ip | Export-Csv c:\YourDirectory\network.csv