VMware Cloud Community
Squigglymonkey
Enthusiast
Enthusiast
Jump to solution

Simple script that exports to csv listing all the custom annotations

I would like to use export-csv in a simple script listing the machine name and all of its custom attributes. I have tried a couple of ways, but they list the server name 8 times, with the annotation and the value next to it, not very usable for the way I need to use it.
I'd like it to look something like this.

Server               Owner          BuiltBy

--------               --------           ----------

server1             doug            bill

server2             Mike            stan

ty!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM | Get-Annotation | Group-Object -Property AnnotatedEntity | %{

   $obj = [ordered]@{

  VM = $_.Name

  }

   $_.Group | %{

   $obj.Add($_.Name,$_.Value)

  }

   New-Object PSObject -Property $obj

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM | Get-Annotation | Group-Object -Property AnnotatedEntity | %{

   $obj = [ordered]@{

  VM = $_.Name

  }

   $_.Group | %{

   $obj.Add($_.Name,$_.Value)

  }

   New-Object PSObject -Property $obj

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Squigglymonkey
Enthusiast
Enthusiast
Jump to solution

Thank you so very much again!

Reply
0 Kudos