datastorename = "your-test-datastore-name"; //Get all datastores var ds = System.getModule("com.vmware.library.vc.datastore").getAllDatastoresMatchingRegexp(datastorename); //Locate a ESXi host that connects to the datastore (from ds into host) esx = ds[0].host[0].key; //Get VimHostDatastore system to be used to gather path and extent dsSys = esx.configManager.datastoreSystem; //Get the local path to vmfsSystem vmfsPath = ds[0].host[0].mountInfo.path; //Identify free space on the lun and put into VcVmfsDatastoreExpandSpec extend = dsSys.queryVmfsDatastoreExpandOptions(ds[0]); //As long as extend is not null if ( extend != null) { extend_spec = extend[0].spec; //expand the volume to max size on disk System.log("Expanding Datastore : " + datastorename); dsSys.expandVmfsDatastore(ds[0], extend_spec); } //Rescan is initiated by the expand for all nodes mounting so it does not need to be done manually