Skip navigation


if you want to add a new vdisk (vmdk file) to a running virtual machine, you can do it via command line.


First, connect to the esxi host where is the placed the vm that you want to add a new vdisk/vmdk.


Then go to the datastore where you want to place the new vdisk/vmdk:

cd /vmfs/volumes/WhatEverDatastore/


Then create the vmdk file using vmkfstools:

vmkfstools -c 150G --diskformat zeroedthick vDisk.vmdk


Finally, add the new vdisk to the virtual machine:


First, get the vmid of the virtual machine:


vim-cmd vmsvc/getallvms


With the vmid, add the vdisk/vmdk:


vim-cmd vmsvc/device.diskaddexisting 464 /vmfs/volumes/WhatEverDatastore/vDisk.vmdk 0 3



Best regards,


P.D: If you want a linux virtual machine be able to detect the new vDisk, check this.


searching the web, a found a nice script that reports orphaned/unused vmdk files:

Virtually Jason: Orphaned VMDK Files


It works so fine, but if do the bad praxis of having datastores with the same name in different vmware hosts, then it doesn't work.


I have modified the script to make it work in this kind of environments:


$report = @()

$arrUsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}

$arrHost = Get-VMHost


foreach ($vmhost in $arrHost) {


$arrDS = Get-Datastore -VMHost $vmhost | Sort-Object -property Name

foreach ($strDatastore in $arrDS) {

#Write-Output "$($strDatastore.Name) in $host.Name Orphaned Disks:"

$ds = Get-Datastore -Name $strDatastore.Name -VMHost $vmhost | % {Get-View $_.Id}

$fileQueryFlags = New-Object VMware.Vim.FileQueryFlags

$fileQueryFlags.FileSize = $true

$fileQueryFlags.FileType = $true

$fileQueryFlags.Modification = $true

$searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec

$searchSpec.details = $fileQueryFlags

$searchSpec.matchPattern = "*.vmdk"

$searchSpec.sortFoldersFirst = $true

$dsBrowser = Get-View $ds.browser

$rootPath = "[" + $ds.Name + "]"

$searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)



foreach ($folder in $searchResult)


foreach ($fileResult in $folder.File)


if ($fileResult.Path)


$pathAsString = out-string -InputObject $FileResult.Path

if (-not ($arrUsedDisks -contains ($folder.FolderPath + $fileResult.Path))){

# Changed Black Tracking creates ctk.vmdk files that are not referenced in the VMX.  This prevents them from showing as false positives.

if (-not ($pathAsString.toLower().contains("-ctk.vmdk"))){

$row = "" | Select VMHost, DS, Path, File, SizeGB, ModDate

$row.VMHost = $vmhost.Name

$row.DS = $strDatastore.Name

$row.Path = $folder.FolderPath

$row.File = $fileResult.Path

$row.SizeGB = (($fileResult.FileSize/1024)/1024)/1024

$row.ModDate = $fileResult.Modification

$report += $row

#Write-Output "$($row.Path)$($row.File)"















(Remember to use the Connect-VIServer cmdlet before!)




Have fun!



Best regards,