I am trying to export the custom Annotation fields to a csv file with foreach and having trouble get it to work where I want.
1. Is it possiible to export them with foreach or do I have to use foreach-object?
$vms = get-vm pt*
foreach ($vm in $vms){
$vm = Get-View $vm.ID
$nm = $vm.name
$hn = $vm.guest.hostname
$ip = $vm.guest.ipaddress
$contact = get-vm $vms | Get-Annotation -CustomAttribute "System Contact"|select Value
$vm | select `
@{Name = "Name"; E={$nm}},`
@{Name = "Contact"; E={$contact}},`
@{Name = "Hostname"; E={$hn}},`
@{Name = "IP"; E={$ip}}
}format-table -AutoSize -Wrap
2. How can I get rid of the "{@{Value=" in the output??
Name Contact Hostname IP
---- ------- -------- --
PT1 {@{Value=abcd.Serverteam... pt1.abcd.com 10.0.1.5
PT2 {@{Value=abcd.Serverteam... pt2.abcd.com 10.0.1.33