Squigglymonkey
Enthusiast
Enthusiast

Simple script that exports to csv listing all the custom annotations

Jump to solution

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!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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

0 Kudos
2 Replies
LucD
Leadership
Leadership

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

0 Kudos
Squigglymonkey
Enthusiast
Enthusiast

Thank you so very much again!

0 Kudos