Number of VMs in Datastore:

Get-Datastore | Select Name, @{N="NumVM";E={@($_ | Get-VM).Count}} | Sort Name

The following script was used to add the datastore’s from a csv file :

$CSVFile = "C:\Temp\Test.csv" ## Where Test.csv is the csv file from where you want to copy from 
$MYESXHost = "Esxi.local" 
$VMHBA = "vmhba2:0:"

Connect-VIServer VCENTERSERVER ##vCenter Server 
$CSV = Import-CSV $CSVFile ## Importing CSV 
$ESXHost = Get-VMHost $MYESXHost 
$ESXHost |Get-VMHostStorage -RescanAllHBA 
Foreach ($Item in $CSV){ 
 $HostID = $Item.HostId 
 $LunID = $Item.LunID 
 Write "Creating SAN_HOST$($HostID)_LUN$($LunID)…" 
 $ESXHost |New-Datastore -Vmfs -Name "SAN_HOST$($HostID)_LUN$($LunID)" -Path "$($VMHBA)$($HostID)" 
}

List all the VMDK files for VMs stored on your local storage:

Get-Datastore |where {$_.Name -match “local“} |Get-VM |Get-HardDisk |select Filename |Export-Csv c:\Test.csv

You can also add multiple names for your local storage by added them with a | .

Get-Datastore |where {$_.Name -match “store|local|storage“} |Get-VM |Get-HardDisk |select Filename |Export-Csv c:\Test.csv

Podcast also available on PocketCasts, SoundCloud, Spotify, Google Podcasts, Apple Podcasts, and RSS.

One response

Leave a reply to Anonymous Cancel reply

The Podcast

Join Naomi Ellis as she dives into the extraordinary lives that shaped history. Her warmth and insight turn complex biographies into relatable stories that inspire and educate.

About the podcast