powershell - Hyper-V 2012R2使用Powershell获取VM快照文件

标签 powershell snapshot hyper-v

我有一个powershell脚本来生成HTML报告,该报告包括所有虚拟机和一台hyper-v服务器的快照。

起初,我使用Get-VM获得了所有虚拟机。然后,我遍历该列表,并使用Get-VMSnapshot获取一个虚拟机的所有快照。

我遇到的问题是,我看不到如何从$VMSnapshot到真实文件以获取其大小。

这是我的代码:

$VMs = Get-VM -ComputerName $Computers
foreach ($VM in $VMs) {
    $VMSnapshots = Get-VMSnapshot -VMName $VM.VMName -ComputerName $VM.ComputerName | Select ComputerName, VMNAME, CreationTime, Path, Name | sort CreationTime
    foreach ($VMSnapshot in $VMSnapshots) {
        #How to get the filesize of that snapshot?
    }
}

我知道,可以使用$VMSnapshotSize gci -Path $VMSnapshot.Path -Filter *.avhd*获取文件大小,但是由于该目录中存在多个快照,因此$VMSnapshot$VMSnapshotSize之间没有关系。

最佳答案

试试这个代码:

Get-VMSnapshot -VMName $VM.VMName | select -ExpandProperty HardDrives | % { Get-VHD $_.Path | select Path, FileSize }

关于powershell - Hyper-V 2012R2使用Powershell获取VM快照文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37301861/

相关文章:

powershell - Start-Process 不执行后 Job 脚本 block 中的代码

amazon-web-services - 将 Amazon EC2 实例还原为快照?

asp.net - 网页快照

c# - 如何重用 Get-VMMServer 连接?

c# - 通过 wmi 类将 vlan 分配给网络适配器

powershell - powershell:创建具有语法错误的通用哈希集?

oracle - 相同的代码但不同的结果

powershell - 如何修改文件夹的上次写入时间和上次访问

elasticsearch - 在Elasticsearch上自动创建快照存储库-Kubernetes

即使安装并启用了 Hyper-V,Visual Studio 中的 Android 模拟器也无法启动