Powershell script to setup NFS share on Server 2012 R2

The following script sets up NFS share on Server 2012 R2:


# Script to setup NFS share on Server 2012 R2
# Sam Boutros – 7/7/2014
# References:,
$NFSFolder = “d:\shares\NFS1” # Tye in the path to the folder to be shared via NFS
$NFSShare = “nfs1” # Type in the share name you wish to use
# End Data entry section
Import-Module ServerManager
Add-WindowsFeature FS-NFS-Service
Import-Module NFS
if (!(Test-Path $NFSFolder)) {New-Item -ItemType directory -Path $NFSFolder}
New-NfsShare -name $NFSShare -Path $NFSFolder
$ShareName = $env:COMPUTERNAME + “:/” + $NFSShare
Write-Output “NFS share has been created: $ShareName”

You can see the new share in Server Manager under File and Storage Services:


The default NFS share properties are:



Under Share Permissions, I clicked Add, entered the IP address (or name) of the Linux host that needs to connect to this 2012 R2 NFS share, and selected the desired access (read/write):


No changes to NTFS permissions:


Finally, I enabled the following firewall rule to allow me to ping this server:NFS8

Next, I setup a Red Hat 6.5 VM to test with.  I picked v6.5 because

  1. It comes with the Hyper-V integration built in – no need for manual RTM installation,
  2. The Hyper-V integration server for 6.5 kernel allows for Host-based VSS backup – no need for guest agent inside the Linux machine. We get crash consistent backup (not application consistent backup), but that’s a big improvement from Hyper-V integration service for kernel version 6.4 and older,
  3. The Hyper-V integration service supports dynamic RAM. Again, with kernel versions 6.4 and older, we can only use static RAM with Linux guests

I downloaded the media ISO Boot and DVD files from Red Hat,

created VM with 2 DVDs so that I can mount both media during setup, followed the simple installation steps, rebooted

Next, I used the console (and later on Putty to SSH) to the new Red Hat machine, logged in as root,


I ran the following commands:

ifconfig -a => show interfaces
ifconfig eth0 netmask => to setup IP address and mask
ping => confirm connection to NFS server (enabled ping rule in Windows firewall)
mount -t ext4 => to show partitions formatted with ext4 file system
mkdir /pub => to create local mount point directory /pub
mount /pub (must have added permission on NFS share on Server 2012)
cd /pub => to change directory to /pub
ls => to see files on remote NFS share
echo hello >test1.txt => to test creating a text file named test1

You might want to edit /etc/fstab and modify the following line to match your configuration. For example: /pub nfs defaults 0 0

The files were visible also on the 2012 R2 server.