Windows Server 2012 ships with a rich set of PowerShell cmdlets to perform most of the Server for NFS share management operations. Using these cmdlets as building blocks, administrators can easily build backup and restore scripts for the NFS share settings and permissions that best suits their needs. This post demonstrates how Export-CliXml and Import-CliXml cmdlets can be used to backup and restore Server for NFS share settings.
Let us take a quick look at the Server for NFS share management cmdlets in Windows Server 2012. If you are not already familiar with these cmdlets please look at their help to get more details on using these cmdlets.
The Export-CliXml cmdlet can be used to export the objects to XML files. Similarly the Import-CliXml cmdlet can be used to import the content of an XML files (generated using Export-CliXml) to their corresponding objects in Windows PowerShell. If you are not familiar with these cmdlets please refer to the PowerShell help section.
To export all the NFS shares on the server invoke Get-NfsShare and pipe the results to Export-CliXml cmdlet.
Get-NfsShare | Export-CliXml -Path c:\shares.xml
Running the above command saves only the share settings into the file. It does not save share permissions. Exporting share permission is covered in next section as the permissions are handled using another set of cmdlets.
The following share settings are exported to the file
Name
NetworkName
Path
IsClustered
IsOnline
AnonymousAccess
AnonymousGid
AnonymousUid
Authentication
UnmappedUserAccess
To export a single share, use the following command. In addition you can also filter the shares that you want to save by using wild cards for the share name, path and network name. See Get-NfsShare help for more details on using it.
Get-NfsShare -name shareA | Export-CliXml -Path c:\shares.xml
To save permissions of all the shares, use Get-NfsShare first to enumerate all the shares on the server. Use a PowerShell pipeline to pass the result to Get-NfsSharePermission to get the permissions for each of the shares. The result of these two commands can then be saved to an export file using the Export-CliXml cmdlet.
Get-NfsShare | Get-NfsSharePermission | Export-CliXml -Path c:\SharePermissions.xml
Similarly to export the permissions of a single share specify the share name in Get-NfsSharePermission.
Get-NfsSharePermission shareA | Export-CliXml -Path c:\SharePermissions.xml
If you have an export file generated using the Export-CliXml containing the share configuration follow these steps to import them on Server for NFS running Windows Server 2012.
We have the choice of using either New-NfsShare or Set-NfsShare when performing the import operation. Use Set-NfsShare if the share already exists on the server and you would like to overwrite it with settings from the exported file.
To create new shares on the server using the export file, use Import-CliXml to read the export file and create objects that can be given as input to New-NfsShare. The following example creates new shares on the server.
Import-CliXml c:\shares.xml | New-NfsShare
The screen shot shows creation of new shares on the server after importing the shares from the export file.
If the shares already exist on the server, the settings of the shares can be restored to that of the export file by piping the output of Import-CliXml to Set-NfsShare cmdlet
Import-CliXml c:\shares.xml | Set-NfsShare
Here is an example to show how this works.
The server has a share with name "ShareA". The "AnonymousGid" and "AnonymousUid" properties of this share are -2 and -2 respectively. The export file "shares.xml" is imported and the share is modified using Set-NfsShare cmdlet which changes the "AnonymousGid" and "AnonymousUid" property of the share to 100 and 200 respectively.
Before we talk about importing share permissions let’s briefly look at the cmdlets that will be used to perform this operation.
A client can be granted readwrite, readonly or no access permission on a share. The client referred to here can be a host machine or a group such as netgroup or clientgroup. Grant-NfsSharePermission cmdlet can be used to add permission for a client if it doesn’t already exist. If permission for a client is already present on the share it can also be modified using same Grant-NfsSharePermisison cmdlet.
To remove client from the list of permissions on a share, use Revoke-NfsSharePermission.
Now let’s get back to importing share permissions from the file. If you have an exported file generated using Export-CliXml that contains the permissions for the shares, use this command to import those permissions.
Import-CliXml C:\sharespermission.xml | foreach{ $_ | Grant-NfsSharePermission}
The import command used above has following implications
Note: If you don’t want to retain existing share permissions on the share, remove them before importing from the file.
Example:
In this example, shareA has following share permissions
The exported file has
After the import operation, the share permissions for ShareA would be
Please send feedback you might have to nfsfeed@microsoft.com
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.