Please enable Javascript for better experience...
Adding NFS datastore to all ESXi Host in One go
By admin | Jul 2, 2017 | In Articles | Total Views [ 28 ]
(0 Like)
Rate

Adding NFS Datasote to all esxi from power-Cli

 

 

--------------------------------------------------------------------------------

# User variables: adjusted for the environment

###################################

# Load VMWare add-ins

if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {

    Add-PSSnapin VMware.VimAutomation.Core

}

# Set location of credentials file

$credsFile = "C:\Scripts\creds.crd"

# import credentials file

$Creds = Get-VICredentialStoreItem -file $credsFile

# NFS Host IP

$nfsHost = "xx.xx.xx.xx"

# NFS share name

$nfsShare = "oursharename"

# New datastore name

$nfsDatastore = "temp"

 

 

 

 

 

####################################################################################################################

# Start Of Execution

####################################################################################################################

 

 

#connect to vCenter using credentails supplied in credentials file

Connect-VIServer -Server $Creds.Host -User $Creds.User -Password $Creds.Password -WarningAction SilentlyContinue | Out-Null

echo "Connected to vCenter"

 

 

echo "starting addition of NFS share to ESXi Hosts"

 

Import-Csv datacenters.csv -UseCulture | %{

       foreach ($esx in (Get-Datacenter -Name $_.dcName | Get-VMhost | Sort Name)){

              $esx | New-Datastore -Nfs -Name $nfsDatastore -NFSHost $nfsHost -Path $nfsShare

              echo "NFS share added to $esx"

       }

}

 

echo "Task completed"

 

 

Disconnect-VIServer -Server $Creds.Host -Force -Confirm:$False

 

 

 

 

Share this

About the Author

admin
admin
Contributer VMwareDiary.com

User's Comments


 
Please SignUp/Login to comment...

Or comment as anonymous...
* Name
* Email ID
Comment