Sasikumar
Sasikumar

Reputation: 101

How to find number of snapshots for a vm using powershell

I am new to PowerShell scripting. I am trying to get number of snapshots have been created for a VM. I am able to get snapshots information of the VM's using the below command.

get-vm Test_sub | Get-Snapshot

It is giving complete information but is there any way I can count the number of snapshots?

Thanks, Sasikumar.

Upvotes: 0

Views: 2305

Answers (1)

Keith Hill
Keith Hill

Reputation: 201662

If Get-Snapshot returns one output for each snapshot then use Measure-Object (alias Measure) to see the count e.g.:

get-vm Test_sub | Get-Snapshot | Measure

If you need the value in a script then:

$count = (get-vm Test_sub | Get-Snapshot).length

Upvotes: 2

Related Questions