Hello,
I'm hoping someone in the community can tell me where I went wrong in the script below. I have some other PowerCLI scripts which work in a similar way to this one, and those work, but this one has a problem. The script is intended to collect information on a number of ESX objects into an array of arrays, $reportfinal, which can then be written out to a CSV file which will have column names for the objects and each row will report the values for RDM related objects for each VM. The problem is that instead of appending the results into the $reportfinal array, the results are overwritten, and even worse, values repeat themselves (e.g. the size of different disks is reported as the same value).
$report = @()
$reportfinal = @()
$VMs = Get-VMHost | Get-VM | Get-View
$rowcoll = "" | select VM, VMController, SCSIBusShare, SCSIBusNumber, SCSIUnitNo, DeviceLabel, SCSISummary, DeviceFilename, DeviceCapKB, DeviceDiskMode,DeviceDiskUUID
ForEach ($VM in $VMs) {
#Clear report array for each VM
$report=@()
Foreach ($SCSI_Controller in ($VM.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "SCSI*" } )) {
$rowcoll.VM = $VM.Name
$rowcoll.VMController = $SCSI_Controller.DeviceInfo.Label
Foreach ($Disk_Key in $SCSI_Controller.Device) {
Foreach ($Disk_Device in ($VM.Config.Hardware.Device | where {$_.key -eq $Disk_Key } )) {
$rowcoll.SCSIBusShare = $SCSI_Controller.SharedBus
$rowcoll.SCSIBusNumber = $SCSI_Controller.BusNumber
$rowcoll.SCSIUnitNo = $Disk_Device.UnitNumber
$rowcoll.DeviceLabel = $Disk_Device.DeviceInfo.Label
$rowcoll.SCSISummary = $SCSI_Controller.DeviceInfo.Summary
$rowcoll.DeviceFilename = $Disk_Device.Backing.Filename
$rowcoll.DeviceCapKB = $Disk_Device.CapacityInKB
$rowcoll.DeviceDiskMode = $Disk_Device.Backing.DiskMode
$rowcoll.DeviceDiskUUID = $Disk_Device.Backing.UUID
}
}
}
#Append the next collection of row data to the report
$report += $rowcoll
#Append the next collection of report data to the final report
$reportfinal += $report
}
$reportfinal | Export-Csv -path D:\temp\SAP_Report_Disks_RDM_Mappings.csv -NoTypeInformation
Note: Some parts of the script were derived from another posting on this forum regarding a script to list RDM information for a list of VM's.
Cheers,
Ed