-
Notifications
You must be signed in to change notification settings - Fork 10
/
New-Datastore.ps1
64 lines (49 loc) · 2.3 KB
/
New-Datastore.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#Login to vCenter Server
$vCenterServer = 'marvel.vcloud-lab.com'
Remove-Module -Name Hyper-V
Import-Module -Name VMware.PowerCLI
Connect-VIServer -Server $vCenterServer -User administrator@vsphere.local -Password P@ssw0rd
#Define your environment
$esxiServer = 'ironman.vcloud-lab.com'
$hbaModel = 'PVSCSI SCSI Controller'
#Esxi server information
$esxi = Get-VMhost $esxiServer
$esxi
#Get HBA storage adapter information
$hostHBA = $esxi | Get-VMHostHba | Where-Object {$_.Model -eq $hbaModel}
$hostHBA
#Get the list of Datastore
$datastore = Get-Datastore
$datastore
#Get available LUN storage devices list
$lunList = $hostHBA | Get-ScsiLun
$lunlist | Format-Table -AutoSize
#Get the list of LUN on datastores are created
foreach ($lun in $lunList)
{
$lun | Select-Object CanonicalName, RuntimeName, CapacityGB, @{Label='DatastoreName'; Expression={$datastore | Where-Object {$_.Extensiondata.Info.Vmfs.Extent.DiskName.Contains($lun.CanonicalName)} | Select-Object -ExpandProperty Name}}
}
#Rescan/Refresh Esxi Storage
$esxi | Get-VMHostStorage -Refresh -RescanAllHba
#Get get the newly discovered LUN information
$lunList = $hostHBA | Get-ScsiLun
$lunlist | Format-Table -AutoSize
foreach ($lun in $lunList)
{
$lun | Select-Object CanonicalName, RuntimeName, CapacityGB, @{Label='DatastoreName'; Expression={$datastore | Where-Object {$_.Extensiondata.Info.Vmfs.Extent.DiskName.Contains($lun.CanonicalName)} | Select-Object -ExpandProperty Name}}
}
#Get the RuntimeName of Lun (Local as well as Remote shared storage)
$addedNewLun = $lunlist | Where-Object {$_.CanonicalName -eq 'mpx.vmhba0:C0:T2:L0'}
$addedNewLun | Format-Table -AutoSize
#Add new Datastore using RuntimeName of newly Added Lun
$datastoreName = '5gb_local_datastore'
New-Datastore -VMHost $esxi.Name -Name '5gb_local_datastore' -Path $addedNewLun.CanonicalName -Vmfs -FileSystemVersion 6
#Recheck Datastore list
$datastore = Get-Datastore
$datastore
#Recheck LUN and Datastore mapping
$lunList = $hostHBA | Get-ScsiLun
foreach ($lun in $lunList)
{
$lun | Select-Object CanonicalName, RuntimeName, CapacityGB, @{Label='DatastoreName'; Expression={$datastore | Where-Object {$_.Extensiondata.Info.Vmfs.Extent.DiskName.Contains($lun.CanonicalName)} | Select-Object -ExpandProperty Name}}
}