VMware Cloud Community
RoyalFlash
Enthusiast
Enthusiast

Edit Annotation - Each VM with different "purpose" description

Hi all,

i want to set each VM with a different description.

ForEach ($VM in Get-Content D:\VM.txt) {

  ForEach ($Purpose in Get-Content D:\Purpose.txt) {

Set-Annotation -Entity $VM -CustomAttribute "Purpose" -Value $Purpose
}
}

 

But now, each VM is getting all "purpose" descriptions, before the script start to edit the next VM in the VM.txt list

How will

VM1 get purpose description 1

VM2 get purpose description 2 

VM3 get purpose description 3

RoyalFlash_0-1649429871880.png

 

0 Kudos
2 Replies
LucD
Leadership
Leadership

The easiest would be if you combine those 2 files in 1 CSV file.

But with your files you could do

$vmNames = Get-Content D:\VM.txt
$purpose = Get-Content D:\Purpose.txt

0..($vmNames.Count - 1) | foreach {
  Get-VM -Name $vmNames[$_] : Set-Annotation -CustomAttribute 'Purpose' -Value $purpose[$_]
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
RoyalFlash
Enthusiast
Enthusiast

Thanks!!!

Working!!!

You saved my life 😃

Have a nice weekend

0 Kudos