Home > Scripting, Systems, Virtualization > Scripting: PowerCLI–Adding New Datastore

Scripting: PowerCLI–Adding New Datastore

Recently, I came up with a need to add a new NFS datastore to one of our datacenter clusters. The NFS location holds our ISOs for VM building. The cluster is not huge by any means, but I thought it would be worth taking the time to script it out.

In the name of community, sharing, and helping people out, I present… My script!

# Connect to your vCenter instance $vcenter = Connect-VIServer -Server vcenter.domain.local -User Administrator -Password supersecretadminpassword # Connect to the proper cluster managed by vCenter $cluster = Get-Cluster CluserName # Get the hosts inside of the specific cluster $clusterhosts = $cluster | Get-VMHost # Iterate through the group of VM hosts and perform an action on each host # In this example, we will be adding a new datastore foreach ($esxhost in $clusterhosts) { # Create the new datastore on the ESX/ESXi host. New-Datastore -VMhost $esxhost -Name "ISOStore2" -Path "/mnt/isostore" -Nfs -NfsHost nfsserver.domain.local -ReadOnly } #Disconnect the open session from the vCenter server Disconnect-VIServer -Server $vcenter

While I know this may seem a little basic, the fact is that it provides a great start for some PowerCLI scripting and may save you some time in connecting the datastores to the cluster hosts like it did for me.

Happy scripting!

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: