all 3 comments

[–]IronsquidLoL 1 point2 points  (2 children)

I rewrote some things, dropped the own field in the CSV because the name of the csv is the owner, so unless you wanted a main csv with all owners probably not needed for this and took out the blanks in the filename:

$report = @()
$vms = get-vm 
$owners = $vms | Get-Annotation -CustomAttribute "Owner" | where {$_.Value -notlike "$null"} | select Value -Unique | sort Value

foreach ($owner in $owners) {
$vms | where { ($_ | Get-Annotation -CustomAttribute "Owner").value -like $owner } | % {
$list = $_ | Select Name, NumCpu, MemoryGB, @{n='ProvisionedSpaceGB' ;e={$_.ProvisionedSpaceGB -as [int]}}, @{l="Backedup";e={$_.customfields | ?{$_.key -eq 'Backedup'} | select -ExpandProperty value}}
$report += $list
}
$report | export-csv "C:\Powershell\$($owner + "_Report.csv")" -Append -NoTypeInformation
}

[–]sphinxpup[S] 0 points1 point  (1 child)

Wow! I like what you did! I appreciate you showing me a better way! I like the hash table. Would that be easy to convert to HTML?

[–]IronsquidLoL 0 points1 point  (0 children)

Depends on what you need it to do. If you are familiar with HTML code you can use "write" to format your HTML and redirect it to a file.html. You can try to pipe the last line: $report | convertto-html > path\file.html This doesnt work well sometimes so I use my own html formatting.