Upgrading your VMFS datastores with PowerCLI
June 5, 2013 2 Comments
With the release of VMware vSphere 5.0 a new version of the VMFS datastores was released also: VMFS-5. This new VMFS-5 version has a lot of advantages over the old VMFS-3 version (see for information about the new features Cormac Hogan’s post vSphere 5.0 Storage Features Part 1 – VMFS-5). You can upgrade your VMFS-3 datastores to VMFS-5 while VM’s on the datastores keep running. In this post I will show you the vSphere PowerCLI Upgrade-VmfsDatastore function that will do the upgrade for you.
The Upgrade-VmfsDatastore function
The Upgrade-VmfsDatastore function is a PowerShell advanced function that will accept input from the pipeline. You can specify the datastores that you want to upgrade as input. If you use the -WhatIf parameter, it will only show what the function would do, but it will not do it. This is a great way to see in advance which datastore can be upgraded if you use the output of the Get-Datastore cmdlet as input.
function Upgrade-Vmfsdatastore {
<#
.SYNOPSIS
Upgrades a VMFS datastore.
.DESCRIPTION
Upgrades a VMFS datastore from VMFS 3 to VMFS 5.
.PARAMETER Datastore
Specifies the datastores you want to upgrade.
.PARAMETER WhatIf
Shows what would happen if the function runs. The function is not run.
.EXAMPLE
PS C:\> Upgrade-VmfsDatastore -Datastore (Get-Datastore -Name Datastore1,Datastore2)
Upgrades VMFS datastores Datastore1 and Datastore2 to VMFS 5.
.EXAMPLE
PS C:\> Get-Datastore | Upgrade-VmfsDatastore
Upgrades all VMFS datastores to VMFS5.
.INPUTS
VmfsDatastoreImpl
.OUTPUTS
VmfsDatastoreImpl
.NOTES
Author: Robert van den Nieuwendijk
Date: 11-10-2016
Version: 1.1
.LINK
https://rvdnieuwendijk.com/
#>
[CmdletBinding()]
[OutputType([VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl])]
param(
[parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl[]] $Datastore,
[Switch] $WhatIf
)
process {
foreach ($CurrentDatastore in $Datastore |
Where-Object {
$_.GetType().Name -eq 'VmfsDatastoreImpl' -and $_.FileSystemVersion -lt 5
}
)
{
# If -WhatIf is used, only show what the function would do and don't do it
if ($WhatIf)
{
Write-Output "What if: Performing operation Upgrade-VmfsDatastore on Target $($CurrentDatastore.Name)."
}
else
{
# Get the HostStorageSystem of the first host that the datastore is connected to
# The UpgradeVmfs() method of this object is used to upgrade the datastore
$HostStorageSystem = $CurrentDatastore |
Get-VMHost | Select-Object -First 1 |
Get-VMHostStorage | Get-View
# Construct the path to the volume to upgrade
# For example: /vmfs/volumes/4e97fa06-7fa61558-937e-984be163eb88
$Volume = '/' + $CurrentDatastore.ExtensionData.Info.Url.TrimStart('ds:/').TrimEnd('/')
# Upgrade the datastore
$HostStorageSystem.UpgradeVmfs($Volume)
# Return the datastore that has been upgraded
$CurrentDatastore
}
}
}
}
Listing 1. The Upgrade-VmfsDatastore function
There are some examples in the Upgrade-VmfsDatastore function’s comment-based help. Here are some more:
PowerCLI C:\> Get-Datastore -Name Datastore1 | Upgrade-VmfsDatastore -WhatIf
What if: Performing operation Upgrade-VmfsDatastore on Target Datastore1.
PowerCLI C:\> Get-Datastore -Name Datastore1 | Upgrade-VmfsDatastore
Name FreeSpaceGB CapacityGB
—- ———– ———-
Datastore1 103,861 499,750
I would love to hear it when you use the Upgrade-VmfsDatastore function to upgrade your datastores.
Enjoy!




Hi,
Excellent script, and I’m looking to use it to upgrade over 200 datastores after a recent upgrade from 4.0 to 5.5.
Should $datastore on lines 60 & 78 actually be $CurrentDatastore?
I ran it against 1 datastore with -whatif, and the Target was blank until I changed $Datastore to $CurrentDatastore.
I then ran it against 2 datastores using Example 1 in the script, and it output both datastores for each upgrade.
Thanks again for an excellent script, you are definitley one of the PowerCLI deities 🙂
Hi Tony,
Thanks for your comment. I am glad you like the Upgrade-VmfsDatastore function. You are correct about the lines 60 and 78. I have modified the script accordingly.
Robert