Renaming a datastore through vCO

1 minute read

I was in need of automatically renaming a generic datastore name in one of my host deployment workflows and found that the renameDatastore() method was deprecated (Thanks Jörg!) and that we are to use rename_Task().  The rename_Task() method is one that takes any manageable object.  Here is an exert from the API reference:


Renames this managed entity.

Any % (percent) character used in this name parameter must be escaped, unless it is used to start an escape sequence. Clients may also escape any other characters in this name parameter.
See [name]

Required Privileges
When object is VirtualMachine - VirtualMachine.Config.Rename
When object is Datacenter - Datacenter.Rename
When object is Folder - Folder.Rename
When object is VirtualApp - VApp.Rename
When object is ResourcePool - Resource.RenamePool
When object is ClusterComputeResource - Host.Inventory.RenameCluster
When object is DistributedVirtualSwitch - DVSwitch.Modify
When object is DistributedVirtualPortgroup - DVPortgroup.Modify
When object is Datastore - Datastore.Rename
When object is Network - System.Read

So I implemented the following code into a new scriptable task within my workflow:

var hostDatastoreSystem = VcPlugin.toManagedObject( host, host.configManager.datastoreSystem );

// Rename datastore on host matching Datastore
for each (var datastore in hostDatastoreSystem.datastore) {
if( == "Datastore"){
System.log("Changing datastore name to "+newDsName);

Another thing I realized was that the API explorer within vCO is not always as forthcoming with information so a word to the wise, always check the API reference ( for more detailed information.

Leave a Comment