Obtener propiedades de discos de las VM de Hyper-V con PS

Les comparto un script creado por Nahuel Villar en PowerShell para crear un reporte en excel sobre los tipos de discos en las maquinas virtuales. estos esta bueno para saber que tipo de discos tienen las VM y el espacio que tiene cada host.
Requisitos, deben  tener excel y un archivo con la lista de los Host Hyper-V en c:\temp\servers.txt y les creara un excel con la informacion en c:\scripts\processes.xlsx.  Cambiar la variable "SystemCenterVMM" por el servidor de VMM.

 

Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

Get-VMMServer –Computername SystemCenterVMM

$objExcel = New-Object -ComObject Excel.Application

$wb = $objExcel.Workbooks.Add()

$item = $wb.Worksheets.Item(1)

$objExcel.Visible = $True

#$procs = Get-vm

$a = Get-Content "C:\Temp\Servers.txt"

$i = 1

$item.Cells.Item($i,1) = "Server"

$item.Cells.Item($i,2) = "Type VHD"

$item.Cells.Item($i,3) = "Path Location"

$item.Cells.Item($i,4) = "Host Hyper-V"

$item.Cells.Item($i,5) = "Size Total (GB)"

$item.Cells.Item($i,6) = "Size Maximo (GB)"

$i = 2

foreach ($h in $a)

{

      $procs = Get-VirtualHardDisk -vm $h

      foreach ($p in $procs)

      {

            $item.Cells.Item($i,1) = $h

            IF ($p.VHDType -eq 1)

            {

                 $item.Cells.Item($i,2) = "Dynamically Expanding"

                  $item.Cells.Item($i,6) = $p.MaximumSize/1024/1024/1024

            }

      IF ($p.VHDType -eq 2)

            {

                 $item.Cells.Item($i,2) = "Fixed Size"

                  $item.Cells.Item($i,6) = "N/A"

            }

            IF ($p.VHDType -eq 3)

            {

                 $item.Cells.Item($i,2) = "Differencing"

                  $item.Cells.Item($i,6) = "N/A"

            }

      $item.Cells.Item($i,3) = $p.Location

            $item.Cells.Item($i,4) = $p.VMHost

            $item.Cells.Item($i,5) = $p.Size/1024/1024/1024

           

           $i++       

      }

}

$wb.SaveAs("C:\Scripts\Processes.xlsx")

# Close Excel and clean up

$objExcel.Quit()

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($wb) | Out-Null

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($item) | Out-Null

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel) | Out-Null

[System.GC]::Collect()

[System.GC]::WaitForPendingFinalizers()

Remove-Variable objExcel

Remove-Variable wb

Remove-Variable item

 

Ud esta Aqui:
Citrix Technology Professionals