Mass edit a custom attribute in VMWare

David Sankovsky
David Sankovsky used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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

Author

Commented:
Thanks, I'll check that in a few minutes and will update you

Author

Commented:
That solved it, thanks a lot.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial