Skip navigation


if you want to list all the powered-on virtual machines without vmware tools installed, you can use this powercli script:


# Change the value of this variable (regular expression), if you would want just some datastores (not all) from the script's output



get-vm | where-object {$_.powerstate -ne "PoweredOff" } | % { get-view $_.ID } | where-object { ($_.Datastore -match $datastores) -and ($_.guest.toolsstatus -Notmatch ".*Ok.*") } | select Name


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


The script is based in this script.



Best regards,



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,



If you want get the RDMs defined in your vmware environment using PowerCLI, then you can just use this:



$allvms = Get-VM


foreach ($vm in $allvms) {


    $vmrdm = Get-HardDisk -VM $vm -DiskType "RawPhysical","RawVirtual"


    foreach ($rdm in $vmrdm) {


        if ($rdm.Name) {

        $row = "" | select Parent,Name,DiskType,ScsiCanonicalName,DeviceName,FileName,CapacityGB


        $row.Parent = $rdm.Parent

        $row.Name = $rdm.Name

        $row.DiskType = $rdm.DiskType

        $row.ScsiCanonicalName = $rdm.ScsiCanonicalName

        $row.DeviceName = $rdm.DeviceName

        $row.FileName = $rdm.FileName

        $row.CapacityGB = ($rdm.CapacityKB/1024)/1024




        $report += $row } # End if ($rdm.Name)



} # End foreach ($rdm in $vmrdm)



} # End foreach ($vm in $allvms)










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



Best regards,



P.D: Got from this vmware's KB