Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Add NFS datastores to VMware ESXi hosts using PowerCLI

Warning: Windows NFS server is not listed on VMWare HCL as Esxi NFS datastore. I am using it as a demo purpose.

In this article I will use NFS mount created earlier in Microsoft Powershell: Windows 2016 Install and configure NFS server. Mounting the same NFS datastore storage on Esxi servers or cluster using vSphere PowerCLI, It is best way to automate and make it task easy. All the tasks are performed using command lines only.

First simple one-liner command to add Nfs storage is as below. It will add datastore on one esxi host at a time, You can use multiple esxi host name separating comma (,), or use the command using different esxi host names as shown in the screenshot.
Get-VMHost esxi001.vcloud-lab.com | New-Datastore -Nfs -Name nfs01 -Path /nfs01 -NfsHost 192.168.34.11

To verify datastore is mounted correctly use command.
Get-VMHost esxi001.vcloud-lab.com | Get-Datastore

To know and verify nfs datastore is mounted on which esxi servers use,
Get-Datastore nfs01 | Get-VMHost

VMWARE VSPHERE POWERCLI INSTALLATION AND CONFIGURATION STEP BY STEP
Different ways to bypass Powershell execution policy :.ps1 cannot be loaded because running scripts is disabled

vmware vsphere web client, vcenter esxi powercli, get-vmhost, New-datastore, nfs, network file system, nfs path, get-datastore, esxi vmware datastore storage.png

Here in next task you might need to remove datastore from esxi server, first make sure There are no VMs exist on the storage and no dependency, use. No results are showing means no VMs on the datastore.
Get-Datastore nfs01 | Get-VM

vmware vsphere web client, vcenter esxi powercli, get-vmhost, New-datastore, nfs, network file system, nfs path, get-datastore, esxi vmware datastore storage, Get-vm, no data

After confirming no VMs present, use below command to unmount NFS datastore from multiple esxi servers.
Get-VMHost esxi001.vcloud-lab.com, esxi002.vcloud-lab.com | Remove-Datastore -Datastore nfs01 -Confirm:$false

I am using same command techique, Earlier used for single ESXi servers to mount NFS datastore, but different way, Below command mounts/add storage on all esxi servers in Cluster.
Get-Cluster Cluster01 | Get-VMHost | New-Datastore -Nfs -Name nfs01 -Path /nfs01 -NfsHost 192.168.34.11

Same way I am removing datastore from a cluster instead individual ESXi.
Get-Cluster Cluster01 | Get-VMHost | Remove-Datastore -Datastore nfs01

To verify NFS datastore not exists in the vCenter or a Cluster, I am fetching datastore result from all esxi servers in the Cluster, NFS datastore is not listed here.
Get-Cluster | Get-VMHost | Get-Datastore

vmware vsphere esxi vcenter powercli, get-vmhost, remove-datastore, nfs, network filesystem, get-cluster, get-datastore, add mount datastore storage esxi

Earlier useful posts
Mount NFS share to multiple ESXi hosts
VMWare ESXi add and create NFS datastore
Microsoft Windows 2016 Install and configure NFS server for ESXi and Linux
Unmount NFS datastores from VMware ESXi and NFS is in use

Go Back

Comment

Blog Search

Page Views

1293442

Follow me on Blogarama