VMware Cloud Community
vespavbb
Enthusiast
Enthusiast

Copy custom Attribute from vm to vm

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 ??

VCP4,VCP5,VCP6,VCP7,VCP8
Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

Try like this

$sourceVM = Get-VM -Name "vmtest01"

$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

Reply
0 Kudos
vespavbb
Enthusiast
Enthusiast

thanks..

VCP4,VCP5,VCP6,VCP7,VCP8
Reply
0 Kudos