Hi,
how can I copy Custom Attributes from VM to VM?
here I have an arry with inputs from the source vm, but how can I set these fileds on the target vm?
########
$sourceVM = get-vm -name "vmtest01"
$TargetVM = get-vm -name "vmtest02"
$valueList =@()
$sourceVM | ForEach-Object {
for($i = 0; $i -lt $_.CustomFields.Count; $i ++ ){
$row = "" | Select-Object VMname, FieldKey, FieldValue
$row.VMname = $_.Name
$row.FieldKey = $_.CustomFields.Keys[$i]
$row.FieldValue = $_.CustomFields.Values[$i]
$valueList += $row
}
}
$valueList
####
$TargetVM | Set-Annotation -CustomAttribute ??
Try like this
$TargetVM = Get-VM -Name "vmtest02"
Get-Annotation -Entity $sourceVM |
ForEach-Object -Process {
Set-Annotation -Entity $TargetVM -CustomAttribute $_.Name -Value $_.Value -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks..