Mass edit a custom attribute in VMWare

Hi everyone.
I'm using a lot of automated RVTools scripts to obtain a lot of information about our virtual environments.
Problem is, I got into the company long after many mistakes were when people didn't thing everything through. For that reason,
Many servers are in wrong folders, and many folders are misnamed and etc.
To get some of the information I need, I have to be able to identify the client. I added a global custom attribute called "Client"
Is there a way to bulk edit this folder according to the folder?
I have PowerCli enabled and installed but I don't know it well enough to construct such a script
What I got so far is this:
# Add the vmware snapin for powershell
Add-PSSnapin VMware.VimAutomation.Core
# Your vcenter server and credentials
$vcenter = <<>><<>>
$username = <<>><<>>
$password = <<>><<>>
# Establish Connection
connect-viserver -server $vcenter -user $username -password $password
# Folder in which the Machines that are to be renamed
$Foldername = <<>><<>>
# get a list of servers from the sourceLocation
$vmservers = Get-VM -Location $sourceLocation
# Name of the client that has to be added
$clientname = <<>><<>>

Open in new window


But I can't for the life of me figure out how to loop through the servers and update that custom property.
Any help?
LVL 8
David SankovskySenior SysAdminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SreRajCommented:
Hi,

You could try the following code for modifying value of client attribute. This code need to be appended to the code you specified above. Please try this out in a test environment before trying out in production.

# Loop thru the VM Servers List
ForEach($VMServer in $VMServers){
	#Set value for CustomAttriute Client
	Set-Annotation -Entity $VMServer -CustomAttribute "Client" -Value $ClientName
}

Open in new window


Following is the documentation for Set-Annotation cmdlet.

https://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Set-Annotation.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David SankovskySenior SysAdminAuthor Commented:
Thanks, I'll check that in a few minutes and will update you
0
David SankovskySenior SysAdminAuthor Commented:
That solved it, thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VMware

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.