
Já passou por um situação onde precisou listar o tamanho que os VHDs de suas VMs estão ocupando em um Cluster?
Nesse rápido post irei demonstrar como listarmos todas as VMs e detalhes dos seus respectivos VHDs em um cluster Hyper-V.
No comando abaixo iremos apresentar o path dos VHDs, o nó do cluster onde está alocado, o tipo do VHD e o seu tamanho.
Segue exemplo:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-VM -ComputerName (Get-ClusterNode) | | |
ForEach-Object {Get-VHD -ComputerName $_.ComputerName -VMId $_.VMId} | | |
Select path,computername,vhdtype,@{label='Size(GB)';expression={$_.filesize/1gb -as [int]}} |
Podemos também executar o mesmo comando somente em uma linha, veja o exemplo:
PS C:\> Get-VM -ComputerName (Get-ClusterNode) | ForEach-Object {Get-VHD -ComputerName $_.ComputerName -VMId $_.VMId} | Select path,computername,vhdtype,@{label='Size(GB)';expression={$_.filesize/1gb -as [int]}} Path ComputerName VhdType Size(GB) ---- ------------ ------- -------- C:\ClusterStorage\VMDATA01... SRVHPV01 Fixed 127 C:\ClusterStorage\VMDATA03... SRVHPV01 Dynamic 15 C:\ClusterStorage\VMDATA03... SRVHPV01 Dynamic 458 C:\ClusterStorage\VMDATA03... SRVHPV01 Dynamic 22 C:\ClusterStorage\VMDATA03... SRVHPV01 Dynamic 4 C:\ClusterStorage\vmdata02... SRVHPV01 Dynamic 15 C:\ClusterStorage\vmdata02... SRVHPV01 Dynamic 6 C:\ClusterStorage\vmdata03... SRVHPV01 Dynamic 73 C:\ClusterStorage\vmdata03... SRVHPV01 Dynamic 18 C:\ClusterStorage\vmdata03... SRVHPV01 Dynamic 24 C:\ClusterStorage\VMDATA03... SRVHPV01 Dynamic 463 C:\ClusterStorage\VMDATA03... SRVHPV01 Dynamic 226 C:\ClusterStorage\VMDATA04... SRVHPV01 Dynamic 40 C:\ClusterStorage\VMDATA02... SRVHPV02 Dynamic 16 C:\ClusterStorage\VMDATA02... SRVHPV02 Dynamic 141 C:\ClusterStorage\VMDATA02... SRVHPV02 Dynamic 15 C:\ClusterStorage\VMDATA02... SRVHPV02 Dynamic 110 C:\ClusterStorage\VMDATA03... SRVHPV02 Dynamic 229 C:\ClusterStorage\VMDATA03... SRVHPV02 Dynamic 341 C:\ClusterStorage\VMDATA03... SRVHPV02 Dynamic 299 C:\ClusterStorage\VMDATA02... SRVHPV03 Dynamic 15 C:\ClusterStorage\VMDATA02... SRVHPV03 Dynamic 722 C:\ClusterStorage\VMDATA02... SRVHPV03 Dynamic 15 C:\ClusterStorage\VMDATA02... SRVHPV03 Dynamic 133 C:\ClusterStorage\vmdata03... SRVHPV03 Dynamic 354 PS C:\>
Exportando o resultado
Se preferir podemos exportar para um arquivo CSV ou gerar um HTML.Exportando para arquivo CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-VM -ComputerName (Get-ClusterNode) | | |
ForEach-Object {Get-VHD -ComputerName $_.ComputerName -VMId $_.VMId} | | |
Select path,computername,vhdtype,@{label='Size(GB)';expression={$_.filesize/1gb -as [int]}} | | |
Export-Csv -Path C:\temp\result.csv |
Exportando para um arquivo HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-VM -ComputerName (Get-ClusterNode) | | |
ForEach-Object {Get-VHD -ComputerName $_.ComputerName -VMId $_.VMId} | | |
ConvertTo-HTML -Property path,computername,vhdtype,@{label='Size(GB)';expression={$_.filesize/1gb -as [int]}} > report.html |
É isso pessoal, espero que seja útil.
Abraços a todos!
Breno Padovan