Saturday, July 24, 2021

PowerCLI script to add datastores

 PowerCLI script to add datastores


Connect-VIServer vcenterserver

$input = Import-Csv C:\Temp\CreateDS\dslist.csv

foreach ($row in $input)

{

    $VMHost=$row.VMHost

    $DSName=$row.DSName

    $Luns=Get-VMHost -Name $VMHost | Get-ScsiLun -LunType disk

    $id=$row.NaaID

    $Naa=($Luns.CanonicalName -Like "*$id*")

    New-Datastore -VMHost $VMHost -Name $DSName -Path $($Luns.CanonicalName -Like "*$id*") -Vmfs -FileSystemVersion 6

}

Disconnect-VIServer vcenterserver -Confirm:$false


<#

Content of dslist.csv

VMHost,DSName,NaaID

ESXiHostname1,DatastoreName1,xxxxxxxxxxxxxxxxxxxxxxx1

ESXiHostname2,DatastoreName2,xxxxxxxxxxxxxxxxxxxxxxx2

ESXiHostname3,DatastoreName3,xxxxxxxxxxxxxxxxxxxxxxx3

#>

No comments:

Post a Comment