Posts Tagged ‘ datastore

Refresh Datastores with PowerShell (oneliner)

As I mentioned in the previous article about Refreshing Datastores I would see if I could make a oneliner for this action and I succeed in doing that.

This is what the line should be:

Get-Datacenter | Get-Cluster -Name "ClusterName" | Get-VMHost |
ForEach { $_ } { Get-VMHostStorage -VMHost:$_ -Refresh }

The result on the PowerCLI would probably look like this:

image

The ‘Recent Tasks’ window in the vSphere client will show you a line with “Refresh Host Storage System” for each server.

Thanks for Arne Fokkema for helping me out with the start of the oneliner ;)

Cheers!

NOTE: Get-Datacenter isn’t really required so the oneliner can actually be shorter ;)

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”.