powershell - 如何在 Hyper-V 中使用 Powershell 删除特定快照
问题描述
亲爱的,
我正在尝试删除我们其中一个虚拟机的特定快照,但所有快照都被删除了。
PS C:\Users\abood> Get-VMSnapshot -VMName KUW-HV01
VMName Name SnapshotType CreationTime ParentSnapshotName
------ ---- ------------ ------------ ------------------
KUW-HV01 OLD Standard 7/22/2020 9:17:48 PM
KUW-HV01 NEW Standard 7/22/2020 9:18:08 PM OLD
PS C:\Users\abood> Remove-VMSnapshot -VMName KUW-HV01 -WhatIf | Where-Object {$_.Name -eq "NEW"}
What if: Remove-VMSnapshot will remove snapshot "NEW".
What if: Remove-VMSnapshot will remove snapshot "OLD".
我怎样才能只删除“新”或“旧”而保留另一个?
提前致谢,
解决方案
大多数对某事物(例如Remove-VMSnapshot
)执行操作的 cmdlet 将允许您将对象通过管道传递到它们中,以指定要对哪些对象执行该操作。例如,您已经习惯于Get-VMSnapshot
获取该特定 VM 的两个快照。然后,您可以使用Where-Object
仅指定要删除的快照并过滤掉任何要保留的快照,如下所示:
Get-VMSnapshot -VMName KUW-HV01 | Where-Object {$_.Name -eq "NEW"}
VMName Name SnapshotType CreationTime ParentSnapshotName
------ ---- ------------ ------------ ------------------
KUW-HV01 NEW Standard 7/22/2020 9:18:08 PM OLD
然后通过管道将Remove-VMSnapshot
其准确指定要删除的内容。
Get-VMSnapshot -VMName KUW-HV01 | Where-Object {$_.Name -eq "NEW"} | Remove-VMSnapshot -WhatIf
这应该导致:
What if: Remove-VMSnapshot will remove snapshot "NEW".
推荐阅读
- java - 应用不刷新列表中的选项
- java - 用 Java 将地图从每日数据转换为每周数据
- deployment - Symfony4 缓存清除抛出您请求了一个不存在的服务“cache.proxy_factory”
- python - python-为什么我的程序告诉我它不可调用
- c# - 查询以获取在表中具有记录的 ID 列表
- docker - 在 Azure 应用服务 Linux 上部署 docker 容器
- c# - 如何在 Asp.NET Core WEB API 中使用 .Net (C#) 在 Payload 中创建具有自定义 JSON 声明的 JWT 令牌
- android - 在活动之间发送监听器
- java - MockHttpServletResponse 与原始 HttpServletResponse 不同
- java - 如何使用 PowerMockito 模拟嵌套的静态方法?