There was a requirement in one of the projects to create multiple (approx. 60) datastores using a PowerCLI script. We wrote a PowerCLI script to perform this operation on multiple LUNs presented to all ESXi hosts in the cluster.
Requirements:
- PowerCLI
- PowerShell 5.1 or later
Script:
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
Connect-VIServer “vCenter_Server_IP_Address/FQDN” -Credential (Get-Credential)
$datanames = Import-Csv ‘C:\Users\Admin\Desktop\File_with_datastore_name_NAA_Ids.csv‘
foreach ($dataname in $datanames)
{
$dataname.Datastore_Name
$dataname.Naa_Id
New-Datastore -VMHost ESXi-01.mycloud.lab -Name $dataname.Datastore_Name -Path $dataname.Naa_Id -Vmfs -FileSystemVersion 6
Get-Cluster -name “Cloud-Clu-01” | Get-VMhost | Get-VMHostStorage –RescanAllHBA
Start-Sleep -Seconds 15
}
Disconnect-VIServer -Confirm:$false
Input File Sample:

Just replace the vCenter_Server_IP_Address/FQDN, Path of File Containing Datastore Names, NAA Ids, ESXi Host, Cluster Name and Sleep Interval after each Datastore creation operation with the details of your environment. BOOM!!
Happy Scripting!!
Was very useful.. thanks for the post