Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 183671

Adding datastores to a standalone host

$
0
0

Hi All

I wrote a script to create datastores for a standalone ESXi host. The script doesnt create any datastores and I can't figure out what's wrong. I don't get any error message, the PowerCLI output is in the screenshot

 

 

$ESXhost4='hostname'

$esxencrypted = get-VICredentialStoreItem -file E:\Scripts\Self_Managed_Build_Scripts\encryptedesx
connect-viserver -server "$ESXhost4" -user $esxencrypted.User -password $esxencrypted.Password


$ct=Get-Content E:\Scripts\Self_Managed_Build_Scripts\datastores.csv | Measure-Object –Line | select -ExpandProperty Lines #count the number of lines in the datastore text file
$i = 0
$count = $ct+1 #additional 1 for boot lun which is not included in the text file
$RuntimeList = Get-ScsiLun -VmHost $ESXhost4 | select RuntimeName


$DB = import-csv E:\Scripts\Self_Managed_Build_Scripts\datastores.csv

foreach ($Data in $DB) {
$Name = $Data.'Datastore Names'
$Size = $Data.Sizes

write-host $Name -BackgroundColor blue -ForegroundColor White
write-host $Size -BackgroundColor blue -ForegroundColor White
Write-Host ""
 
while ($i -le $count) {
    $a = "$i"
    $SingleruntimeName = $RuntimeList[$a].RuntimeName
    write-host "$SingleruntimeName" -BackgroundColor blue -ForegroundColor White

    if ($SingleruntimeName = "*0") {   #skip boot lun, for example vmhba0:C0:T1:L0
        $i++
    } else {
        $runtimeName = "$SingleruntimeName"
       
        $RunTimeSize = Get-VMHost $ESXhost4 | Get-ScsiLun | where {$_.RuntimeName -eq $runtimeName} | select -ExpandProperty CapacityMB
        $RunTimeSizeGB = $RunTimeSize/1024

        if ($RunTimeSizeGB -eq $Size) {
            $dsName = $Name
            $esx = Get-VMHost -Name $ESXhost4
            $lun = Get-ScsiLun -VmHost $esx | where {$_.RuntimeName -eq $runtimeName}
            New-Datastore -VMHost $esx -Name $dsName -Path $lun.CanonicalName -Vmfs 
            $i++
        } else {
            $i++
        }   
    }

    }  
   
}
Disconnect-VIServer * -Confirm:$False

 

 

 

 

 

Here is the datastore input csv file content:

 

Datastore Names                                 Sizes
sl_telstra-msc_tier2_datastore01         470
sl_telstra-msc_tier2_scratch                 5
msc_sl_tier3_h_01                                 420
msc_sl_tier3_h_02                                 420
msc_sl_tier3_h_03                                 660
msc_sl_tier3_h_04                                 660
msc_sl_tier3_h_05                                 280
msc_sl_tier3_h_06                                 350
msc_sl_tier3_h_07                                 350
msc_sl_tier3_h_08                                 400
msc_sl_tier3_h_09                                 110
msc_sl_tier3_h_10                                 90
msc_sl_tier3_h_11                                 25
msc_sl_tier3_h_12                                 85
msc_sl_tier3_h_13                                 35
msc_sl_tier2_h_01                                 180
msc_sl_tier2_h_02                                     30

 

 

 

ca.PNG


Viewing all articles
Browse latest Browse all 183671

Trending Articles