Hi all.
I have written a short script to load my vm names from a .csv file, and print a line of information on each of the attached disks. I fumbled through getting my info and having it print to the screen, but I’m missing something on using the export-csv function- I suspect it is with the positioning of the statement in my script.
What is happening is that the last server in my list is the only one that is written to the output .csv file at the job’s end. I guess that I don’t have a handle on how to use this PSObject properly. I would appreciate if I could get some guidance on how to properly code the export-csv/ feature. I’m sure that I’m just missing something simple here.
Thanks.
write-host ===========================================
$csv_info = Import-Csv C:\Scripts\jd\jdtool.csv
$timestamp = Get-Date -format “yyyy-MM-dd_HH.mm”
foreach ($line in $csv_info) {
$vm = $line.vmname.Trim()
$getvm = Get-VM $vm
$GlobalHDDinfo = Get-HardDisk -VM $vm
$totalHDDs = ($GlobalHDDinfo | group-object | measure-object).count
$report = @()
write-host $vm $totalHDDs
foreach ($vdisk in $GlobalHDDinfo) {
$vDiskSpb = (Get-SpbmEntityConfiguration -HardDisk $vdisk).StoragePolicy
$ctrl = $vdisk.Parent.Extensiondata.Config.Hardware.Device | Where-Object {$_.Key -eq $vdisk.ExtensionData.ControllerKey}
$SCSIid = “$($ctrl.BusNumber):$($vdisk.ExtensionData.UnitNumber)”
$Vmresult = New-Object PSObject
$Vmresult | add-member -MemberType NoteProperty -Name "VMName" -Value $vm
$Vmresult | add-member -MemberType NoteProperty -Name "HDD Name" $vdisk.Name
$Vmresult | add-member -MemberType NoteProperty -Name "VMDK Size (GB)" $vdisk.CapacityGB
$Vmresult | add-member -MemberType NoteProperty -Name "SCSI ID" $SCSIid
$Vmresult | add-member -MemberType NoteProperty -Name "StoragePolicy" $vDiskSpb
$Vmresult | add-member -MemberType NoteProperty -Name "HDD UUID" $vdisk.ExtensionData.Backing.Uuid
$vmresult
$report += $vmresult
}
}
$report | Export-Csv ./tests_diskinfo_out_$timestamp.csv -NoTypeInformation -UseCulture -Append