简体   繁体   English

在PowerCLI中一次删除多个快照

[英]Remove Multiple Snapshots at once in PowerCLI

I am trying to delete old snapshots after patching using PowerCLI. 我尝试使用PowerCLI修补后删除旧快照。 The code i am using now is: 我现在使用的代码是:

Get-VM | Get-Snapshot | Remove-Snapshot -confirm$false

It works great...but it only removes one at a time, and i would like it to do 2-3 at a time. 它很好用...但是一次只能删除一个,我希望它一次可以删除2-3个。 Is this possible? 这可能吗?

Thanks in advance! 提前致谢!

This code will remove multiple snapshots from all virtual machines: 此代码将从所有虚拟机中删除多个快照:

Get-VM | Get-Snapshot | % { Remove-Snapshot $_ -Confirm:$false }

I would recommend selecting a single virtual machine and testing first: 我建议选择一个虚拟机并首先进行测试:

$VM = Get-VM -Name 'My Virtual Machine'
$VM | Get-Snapshot | % { Remove-Snapshot $_ -Confirm:$false }

Tested to work on PowerCLI 6.5. 经测试可在PowerCLI 6.5上使用。

I would recommend taking a look at the 'RunAsync' parameter. 我建议看一下“ RunAsync”参数。 This will create the task and then move onto the next task without waiting for the prior task to complete. 这将创建任务,然后移至下一个任务,而无需等待先前的任务完成。

Example: 例:

Get-VM | Get-Snapshot | Remove-Snapshot -RunAsync -Confirm:$false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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