简体   繁体   中英

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.

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

get-vm Test_sub | Get-Snapshot | Measure

If you need the value in a script then:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM