Can someone help me in getting this script to pull the annotations field of the VM's please?
A VM can have multiple annotations. I am not sure if you want to combine that in the same output as the datastores. The following script lists all the names and values of the VM's annotations:
Get-VM | ForEach-Object { $VM = $_ $VM | Get-Annotation | ForEach-Object { $Report = "" | Select-Object VM,Name,Value $Report.VM = $VM.Name $Report.Name = $_.Name $Report.Value = $_.Value $Report } } | Export-Csv -Path VMAnnotations.csv -NoTypeInformation -UseCulture
A VM can have multiple annotations. I am not sure if you want to combine that in the same output as the datastores. The following script lists all the names and values of the VM's annotations:
Get-VM | ForEach-Object { $VM = $_ $VM | Get-Annotation | ForEach-Object { $Report = "" | Select-Object VM,Name,Value $Report.VM = $VM.Name $Report.Name = $_.Name $Report.Value = $_.Value $Report } } | Export-Csv -Path VMAnnotations.csv -NoTypeInformation -UseCulture
That works thanks.
I tried this script.. Got no errors, but it only put an empty .csv on my desktop.
Any ideas?
Are you connected to a vCenter or an ESXi server ?
You do have custom attributes on your VMs ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I'm connected to vCenter and some but not all vm's have data in the Annotations field.
By "Custom Attributes" I'm assuming you mean data in the Annotations field of the VM. Am I correct in this assumption?
Try it like this
Get-VM | Get-Annotation |
Select @{N="VM";E={$_.AnnotatedEntity.Name}},Name,Value |
Export-Csv -Path VMAnnotations.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is what I'm running from the ISE. (Ignore my Set-PowerCLIConfiguration. I plan to use this script for multiple vCenter Servers..) But it still only places and empty .csv in the -path no errors are thrown.
Add-PSSnapin VMware.VimAutomation.Core -erroraction SilentlyContinue
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false
connect-viserver 'vCenter' -WarningAction SilentlyContinue | out-null Get-VM | Get-Annotation | Select @{N="VM";E={$_.AnnotatedEntity.Name}},Name,Value | Export-Csv -Path $env:userprofile\desktop\VMAnnotations.csv -NoTypeInformation -UseCulture
Set-PowerCLIConfiguration -DefaultVIServerMode Single -Confirm:$false
Sorry I don't know how to paste the code properly in the forum...
