VMware Cloud Community
malabelle
Enthusiast
Enthusiast
Jump to solution

Create a VMFS and add it to all the HOsts of a cluster

Hi, I'm trying to create a script so I can create a datastore and after present it to all hosts of a cluster.

any idea?

Add-PSSnapin "Vmware.VimAutomation.Core"
## ----Créer les  Variables----
#$vcenter = %1
## ----Connexion au VirtualCenter----
$Server = $args[0]
$ClusterName = $args[1]
$VMHost = {Get-Cluster $ClusterName | Get-VMHost}
$Name = $args[2]
$Path = $args[3]
Connect-VIserver $Server

Get-VMHost $VMHost | New-Datastore -Server $Server -Name $Name -Path $Path -Vmfs -Confirm:$false
Get-VMHostStorage -VMHost $VMHost -RescanAllHba -RescanVmfs -Refresh

vExpert '16, VCAP-DCA, VCAP-DCD
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You should be connected before you do the Get-Cluster

You don't need to create the datastore on all nodes in the cluster.

Just 1 host is enough.

And the creation of a new datastore forces a rescan.

So this should be enough

Add-PSSnapin "Vmware.VimAutomation.Core" 
#
# ----Créer les  Variables----
#
$vcenter = %1
#
# ----Connexion au VirtualCenter----

$Server = $Args[0]
$ClusterName = $Args[1]

Connect-VIserver $Server
$VMHost = Get-Cluster $ClusterName | Get-VMHost | Select -First 1

$Name
= $Args[2] $Path = $Args[3] Get-VMHost $VMHost | New-Datastore -Server $Server -Name $Name -Path $Path -Vmfs -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

You should be connected before you do the Get-Cluster

You don't need to create the datastore on all nodes in the cluster.

Just 1 host is enough.

And the creation of a new datastore forces a rescan.

So this should be enough

Add-PSSnapin "Vmware.VimAutomation.Core" 
#
# ----Créer les  Variables----
#
$vcenter = %1
#
# ----Connexion au VirtualCenter----

$Server = $Args[0]
$ClusterName = $Args[1]

Connect-VIserver $Server
$VMHost = Get-Cluster $ClusterName | Get-VMHost | Select -First 1

$Name
= $Args[2] $Path = $Args[3] Get-VMHost $VMHost | New-Datastore -Server $Server -Name $Name -Path $Path -Vmfs -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos