Using vCLI Commands in Scripts
Most administrators run scripts to perform the same task repeatedly or to perform a task on multiple hosts. You can run vCLI commands from one administration server against multiple target servers.
For example, when a new datastore becomes available in your environment, you must make that datastore available to each ESXi host. The following sample script illustrates how to make a NAS datastore available to three hosts (esxi_server_a, esx_server_b, and esxi_server_c).
The sample assumes that a configuration file /home/admin/.visdkrc.<hostname> exists for each host. For example, the configuration file for esxi_server_a has the following contents:
VI_SERVER = esxi_server_a
VI_PASSWORD = xysfdjkat
The script itself adds the NAS datastore by calling the different configuration files.
for i in {"esxi_server_a","esx_server_b","esxi_server_c"}
echo "Adding NAS datastore for $i..."
esxcli --config /host.conf storage nfs add -H <hostname> -s <sharepoint> -v <volumename>
esxcli --config <config.file> storage nfs list