Hi all
Would like to seek your expertise on exporting and importing Virtual Machines annotation & all custom attribute that is located in specific Folder and then create a CSV/XLS report.
Sample:
Location = "Offsite DC"
Foldername = "BUILDS"
You can the following PowerCLI script to export the annotations and all custom attributes of the virtual machines in datacenter Offsite DC and folder BUILDS to a file named VMannotations.csv:
Get-Datacenter -Name "Offsite DC" | Get-Folder -Name "BUILDS" | 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
The following PowerCLI script can be used to import the annotations from the VMannotations.csv file:
Import-Csv -Path VMAnnotations.csv | Where-Object {$_.Value} | ForEach-Object {
Get-VM $_.VM | Set-Annotation -CustomAttribute $_.Name -Value $_.Value
}
I'll give a try ... thanks.