I am attempting to copy a custom attribute field from my production vms to replica vms with the same name, just appended with _replica.
I am terrible at doing loops and not sure how to make it work.
This pulls the field but not sure how to apply them correctly after that.
You could do something like this.
I added the Where-clause after the Get-VM to exclude the replicas.
$caName = 'Creation Date'
$ca = Get-CustomAttribute -Name $caName
Get-VM -PipelineVariable vm |
where{$vm.Name -notmatch "_replica$"} |
Get-Annotation -CustomAttribute $ca -PipelineVariable caObj |
ForEach-Object -Process {
Get-VM -Name "$($vm.Name)_replica" |
Set-Annotation -CustomAttribute $ca -Value $caObj.Value -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this.
I added the Where-clause after the Get-VM to exclude the replicas.
$caName = 'Creation Date'
$ca = Get-CustomAttribute -Name $caName
Get-VM -PipelineVariable vm |
where{$vm.Name -notmatch "_replica$"} |
Get-Annotation -CustomAttribute $ca -PipelineVariable caObj |
ForEach-Object -Process {
Get-VM -Name "$($vm.Name)_replica" |
Set-Annotation -CustomAttribute $ca -Value $caObj.Value -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference