Add NetApp volume to VMware with PowerShell

Add-PSSnapin vmware.vimautomation.core
$vcenter = Read-Host "Virtual Center Server"
$clusterName= Read-Host "CLuster"
$VM_Datastore= Read-Host "VMWare Datastore Name"
$NFS_vol= Read-Host "SAN Volume Name"
$NFS_IP = Read-Host "NFS IP"
Write-Host "Connecting to $vcenter" -ForegroundColor Green
#$cred = Get-Credential
Try{
Connect-VIServer $vcenter -ErrorAction Stop #-Credential $cred | Out-Null
}
catch
{
$ErrorMessage = $_.Exception.Message
$ErrorMessage
break

}

try {



$hosts=get-cluster $clusterName -ErrorAction Stop| get-vmhost
$NFSSTORE='/'+$NFS_vol
foreach ($Process_host in $hosts)
{
$VM_name=$Process_host.Name


write-host "New-datastore -Vmhost $VM_name -NFS -Name $VM_Datastore -Path $NFSSTORE -NfsHost $NFS_IP" -ErrorAction Stop

New-datastore -Vmhost $VM_name -NFS -Name $VM_Datastore -Path $NFSSTORE -NfsHost $NFS_IP -ErrorAction Stop
}


}
Catch
{

$ErrorMessage = $_.Exception.Message
$ErrorMessage
Write-Host 'please Look in VMWare to view Details of the Error'
break
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s