PowerShell to mount NFS datastore to VMware Cluster - Power CLI

 ## This script is intended to request input and mount a datastore for a specific cluster

## Script Developed by Uday Yedluri

## From this line below use everything part of your .ps1 file before execution

## Listed are Input Values like vCenter, Details and creds you should provide post script execution on PS screen


$VCServer = Vcenter1, Vcenter2

$Cluster = Read-Host -Prompt 'VMware Cluster Name'

$NameofDS = Read-Host -Prompt 'Please provide datastore name ---Example: NFSName'

$dspath = Read-host -Prompt 'Please provide datastore path ---- Example: /NFSpath '

$nfshostip = Read-Host -Prompt 'Please provide NFS Host IP --- Example: 10.10.10.5'

$cred = Get-Credential 

Connect-VIServer -Server $VCServer -force -credential $cred -Verbose

$nfsvmhosts = get-cluster $Cluster| Get-VMhost

foreach($nfsvmhost in $nfsvmhosts)

{

   get-vmhost $nfsvmhost | New-Datastore -Nfs -Name $NameofDS -Path $dspath  -NfsHost $nfshostip

 }