Posts Tagged ‘ nfs

Refresh Datastores with PowerShell

When using NFS for your datastores on your SAN (eg. NetApp) and you resize your datastore on the fly it always takes a while before the ESX/vSphere servers refresh the datastore so you can see the new size of the volume.

This can be annoying when you want to create a VM on one of these volumes and ESX still thinks the volume is too small because it hasn’t refreshed it’s datastores yet. Normally I would pick one ESX server where I want to put the VM on for starters and refresh the NFS volume which I want to use:

image

Ofcourse I wanted to make it easier for myself so I wrote a little PowerShell script to refresh the datastores on all ESX Servers in our Cluster. I think it’s also possible to make a oneliner out of this and I will try to create one and if I succeed I’ll post it again ;)

$vcHost = "virtual.center.host"
$vcClusterName = "Your ClusterName"
$vcUser = "username"
$vcPass = "password"

$vcServer = Connect-VIServer -Server:$vcHost -User:$vcUser -Password:$vcPass -WarningAction:SilentlyContinue

$vmHosts = Get-Datacenter | Get-Cluster -Name:$vcClusterName | Get-VMHost | Sort

ForEach ($vmHost in $vmHosts) {
    If (Get-VMHostStorage -VMHost:$vmHost -Refresh -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue) {
        Write-Host $vmHost.Name," host storage information refreshed"
    } else {
        Write-Host $vmHost.Name," host storage refresh failed!"
    }
}

Disconnect-VIServer -Server:$vcServer -Confirm:$false

 

After the script has been running the datastores on all your ESX-servers in the cluster will be refreshed so all resizes  of your NFS volumes on your SAN will be visible and “active”.

List NFS Datastore Usage

Some time ago someone we agreed on putting a minimum of 15 Virtual Machines on each NFS-volume on our NetApp storage. Now, almost a year later we have about 14 NFS volumes and the spreading of the VM’s on the Volumes have become a bit out of the ordinary. Mostly because we didn’t have an easy overview of how many VM’s there are present on each volume or because VM’s needed to be created on a short notice.

Since I’ve been busy with PowerShell I decided to create a nice script/utility to create this overview and to increase our insight in our NFS volumes. At first I made a console script, but soon -while I was discovering the posibilities of PowerShell- I created a GUI for it using PrimalForms.

List NFS Store Usage - Example Output

List NFS Store Usage - Example Output

The source is no rocket science, but I just found the utility very handy/helpful to monitor our storage environment for VMware. If you intend to use this sourcecode, don’t forget to adjust the VirtualCenter hostname and access credentials. Also, the names of our DataStores are all start with “VMWare_NFSxx” and I have a condition running to check if the DataStore name starts with that. You might want to adjust that to your datastore name convention.

Read more