Reply to Message

View discussion in a popup

Replying to:
rtunisi
Contributor
Contributor

Weird issues on VM HardDisk information Script

hello everyone

i am designing some simple script to retrieve VM Hard Disk information with PowerCli and i got some pretty weird issue: i ocasionally get runtime execution errors with vc server disconnection, but after the error, i can retrieve info on the same vcenter with simple commands (like Get-VM for instance). The vc farms still available over viclient and powercli all the time, so it must be something on the code


the steps i use to reproduce the strange behavior:

(Using Powercli 5.5 and Powershell 3.0. Error still happens with Powercli 5.1)

- Connect to vcenter (multiple servers)

- run the command and it eventually gets stuck in line 12 ($ghd = Get-HardDisk (Get-VIObjectByVIView $VMView)) with the error 'Server XXXX is disconnected'

- Run some other command (like get-vm) to certify that server is still connected

sample script is below

Function Get-VMDiskInfo {

  [CmdletBinding()]

  Param (

  [Parameter(Mandatory=$true,

  ValueFromPipeline=$True,

  ValueFromPipelineByPropertyName=$true)]

  [Alias('Name')]

  $VM

  )

  PROCESS{

  $VMView = Get-View -ViewType VirtualMachine -Filter @{"Name" = $VM}

  $ghd = Get-HardDisk (Get-VIObjectByVIView $VMView)

    $output = @()

  ForEach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match “SCSI Controller”})){

  ForEach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | Where {$_.ControllerKey -eq $VirtualSCSIController.Key})){

  $VMSummary = “” | Select  VM,Disk, SCSI, DiskType, DiskFormat, DiskSizeGB, DiskFile

  $VMSummary.VM = $VM

  $VMSummary.SCSI = [string]::Concat($VirtualSCSIController.BusNumber,":",$VirtualDiskDevice.UnitNumber)

  $VMSummary.Disk = $VirtualDiskDevice.DeviceInfo.Label

  #pegando info do Get-Harddisks

  $d = $ghd | ? {$_.Name -match $VirtualDiskDevice.DeviceInfo.Label}

  $VMSummary.DiskType = $d.DiskType

  $VMSummary.DiskSizeGB = [Math]::Round($d.capacityGB,2)

  $VMSummary.DiskFile = $d.filename

  if($d.Disktype -eq "Flat"){

  $VMSummary.DiskFormat = $d.StorageFormat

  }

    

  $output += $VMSummary

            }

  }

            Write-Output $output

  }

}

does anyone have any idea whats going on ?


almost forgot, sorry about the messy code and the poor english...


thanks in advance


Tags (3)
Reply
0 Kudos