Skip to content

Instantly share code, notes, and snippets.

@coza73
Last active August 29, 2015 14:03
Show Gist options
  • Save coza73/dc6c60dd46f1f9c98a30 to your computer and use it in GitHub Desktop.
Save coza73/dc6c60dd46f1f9c98a30 to your computer and use it in GitHub Desktop.
vSphere add storage from list in CSV
########################################################################################################
#
# Powershell Script for vSphere
#
# Script to mass add storage to esxi host/cluster from data in CSV
#
# http://vspherepowershellscripts.blogspot.com.au/2014/07/vsphere-bulk-add-storage.html
########################################################################################################
if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin VMware.VimAutomation.Core
}
# Enter the virtualcenter you wish to connect to
$vCenter = Read-Host "Enter vCenter Name or IP"
Connect-VIServer $vCenter
#Pull Lun information from CSV file
#Format is:
#ESXHost,LunName,LunID
#
#ESXHost = The host to create the VMFS volume on
#LunName = The Datastore Name
#LunID = The CanonicalName of the Lun i.e. naa.60060e80058fc60000008fc600006112
$CSVFile = "C:\Temp\datastores.csv"
$CSV = Import-CSV $CSVFile
Foreach ($Item in $CSV){
$ESXHost = Get-VMHost $Item.ESXHost
$LunName = $Item.LunName
$LunID = $Item.LunID
$Lun = Get-ScsiLun -CanonicalName $LunID -VmHost $ESXHost
Write-host "Creating $LunName $Lun on $ESXHost"
New-Datastore -VMHost $ESXHost -Vmfs -Name $LunName -Path $Lun
}
Disconnect-VIServer -Server $vCenter -Confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment