Add and remove VMware NFS datastores via PowerCLI

Been experimenting with these recently, and they have to be added to or removed from each host individually, which is tedious via the GUI.

Easy via PowerShell/PowerCLI though.

Add:

$hosts = Get-VMHost -Location "RCM"
foreach($VMHost in $hosts){
    Write-Host $VMHost.Name
    New-Datastore -VMHost $VMHost -Name "VM Archive" -Nfs -NfsHost nfs01.rcmtech.co.uk -Path "/vmarchive"
}

Remove:

$hosts = Get-VMHost -Location "RCM"
foreach($VMHost in $hosts){
    Write-Host $VMHost.Name
    Remove-Datastore -VMHost $VMHost -Datastore "VM Archive" -confirm:$false
}
This entry was posted in PowerShell, vSphere and tagged , , , , , , , , . Bookmark the permalink.

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