Description
I wrote this script for automating migration from VMFS volume of your infrastructure.
Please make sure have a backup of all of your virtual machines to prevent any issus.
You must do a CSV file as this example :
"Name" "datastore1" "datastore2"
This script can make a CSV file automaticaly as well, but It’ll add all VMFS in version 5. All of VMFS datastore are showing before Update.
For more information about migration from VMFS 5 to VMFS 6, please following this link : SDK Update-VmfsDatastore
Requirements
- Temporary datastore must be in VMFS version 5
- You must have a CSV or you can generate one by this script
Script
$vCenterServer = "MyvCenter" Connect-VIServer $vCenterServer cls $GetDatastoreName = @() $PathFile = @() $CurentPath = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition) $Date = date | select * $Day = $Date.Day $Month = $Date.Month $Hour = $Date.Hour $Minute = $Date.Minute function Resume ($Path) { $ImportCSV = Import-Csv -Path $Path -Delimiter "," if (!$ImportCSV.Name) { Write-Host "This file doesn't contain any columns Name" -ForegroundColor red break } elseif ($ImportCSV.Name) { foreach ($line in $ImportCSV) { $GetDatastoreName += @($line.Name) } New-Variable -Scope script -Name AllDatastoreName -Value $GetDatastoreName Get-Datastore -Name $GetDatastoreName | select Name,FileSystemVersion,Type | Format-Table } } function upgradeVMFS ($TemporaryDatastore) { foreach ($Datastore in $AllDatastoreName) { if ($Datastore -eq $DatastoreTemp) { Write-Host "Temporary Datastore ($Datastore) is excluded" -ForegroundColor Red } elseif ($Datastore -ne $DatastoreTemp) { $DatastoreSource = Get-Datastore -Name $Datastore $DatastoreTemp = Get-Datastore -Name $TemporaryDatastore $Server = (Get-VIServer -Server "$vCenterServer") Update-VmfsDatastore -Server $Server -Datastore $DatastoreSource -TemporaryDatastore $DatastoreTemp -Force } } } ######### Awnsers do { $CSVFile = Read-Host "Did you make any CSV file ? [y/n] " } while ((!$CSVFile) -or (($CSVFile -ne "y") -and ($CSVFile -ne "n"))) if ($CSVFile -eq "y") { do { $PathFile = Read-Host "File path " $ValidPath = Test-Path -Path $PathFile -Include *.csv } while ((!$PathFile) -or (!$ValidPath)) } elseif ($CSVFile -eq "n") { $filenameExport = "$Day."+"$Month."+"$Hour."+"$Minute."+"GetDatastoreCSV.csv" Get-Datastore | select Name,FileSystemVersion,Type | where {$_.FileSystemVersion -le "6"} | Export-Csv $CurentPath"\"$filenameExport $PathFile = "$CurentPath\$filenameExport" } Write-Host "File is stored : $PathFile" Resume -Path $PathFile do { $VarConfirm = Read-Host "Do you agree with these informations ? [y/n]" } while ((!$VarConfirm) -or (($VarConfirm -ne "y") -and ($VarConfirm -ne "n"))) if ($VarConfirm -eq "y") { do { $TempDatastore = Read-Host "Please enter Temporary Datastore Name (VMFS 5) " } while (!$TempDatastore) $CheckDatastore = Get-Datastore -Name $TempDatastore if (!$CheckDatastore) { Write-Host "Temporary Datastore ($TempDatastore) is not valid" break } elseif ($CheckDatastore) { $GetDatastoreName = $script:GetDatastoreName upgradeVMFS -TemporaryDatastore $TempDatastore } } elseif ($VarConfirm -eq "n") { break }