#Autentification et connection au vCenter

$credentialvCenter = Get-Credential administrator@vsphere.local
$vc = Connect-VIServer -Server vcsa.vmware.lab -Credential $credentialvCenter

$ESXI = (Get-Cluster -Name "PowerCLI-HA-DRS" | Get-VMHost)

Write-Host "Scan du Stockage sur les ESXI du Cluster"

Get-Cluster -Name "PowerCLI-HA-DRS" | Get-VMHost | Get-VMHostStorage -RescanAllHBA

Start-Sleep 6

Write-Host " Avtivation du Flag VSAN sur le VMkernel pour tous les hôtes ESXI du Cluster"
foreach ($vesxi in $ESXI)
    {
    Get-VMHost -Name $vesxi | Get-VMHostNetworkAdapter | where { $_.PortGroupName -eq "Management Network" }`
     | Set-VMHostNetworkAdapter -VsanTrafficEnabled $true -Confirm:$false
     
    }

# Désactivation de HA sur le CLuster

Write-Host "Desactivation du HA sur Le cluster"

$VSANCluster = (Get-Cluster -Name "PowerCLI-HA-DRS") | Set-Cluster -HAEnabled $false -Confirm:$false -ErrorAction SilentlyContinue


# Activation de VSAN sur le CLuster
Write-Host "Desactivation de VSAN sur Le cluster"

$VSANCluster = (Get-Cluster -Name "PowerCLI-HA-DRS") | Set-Cluster -VsanEnabled:$true -VsanDiskClaimMode Automatic -Confirm:$false -ErrorAction SilentlyContinue

# Activation de HA sur le CLuster

Write-Host "Activation du HA sur Le cluster"

$VSANCluster = (Get-Cluster -Name "PowerCLI-HA-DRS") | Set-Cluster -HAEnabled $false -Confirm:$false -ErrorAction SilentlyContinue
