Managing shared folders in Windows Failover Cluster with Powershell

I’ve been using Powershell more and more lately, most of the time the motivation has been to do repeatable tasks much more quickly and efficiently but there has also been other cases where Powershell has been the only way to accomplish something. Most often this is due to lacking GUI or Windows issues that have prevented me from using the GUI in the first place. This post describes the latter scenario and the Powershell workaround.

I was building a database cluster for one of our customers and part of the HA/DR/Reporting solution for that environment is to set up a Log Shipping to create a copy of databases to a secondary server. Log shipping requires a shared folder through which the transaction log backups are copied and we usually create this into the same cluster group than the SQL Server.  I started my usual routine, going to Failover Cluster Manager GUI, picking the role I wanted to add the shared folder into and then I clicked “Add File Share”. A window popped open, like the one below.

no_go

It remained there for a while and then disappeared, I waited for a moment and then tried it again and the exactly same thing happened. Few reboots and some more attempts later it was obvious that doing this through GUI would not work. It did something though, as I saw this kind of error at the GUI.

the_error

Couple Internet searches later I found some articles and posts saying that this is something that could happen in Windows and creating shared folders with Powershell should still work. None of these posts actually gave any advice on how to do that exactly, but finding it out wasn’t really that difficult. I knew I was looking for a way to create a share, so I fired up Powershell console and ran the following command.

Get-Command -Noun *share*

If you ever need to figure out what cmdlet to use, Get-Command is your friend. If you only can remember single cmdlet, make it this one Smile In my case I got the following listing.

powershell_get_command

New-SmbShare looked promising so I checked the cmdlet help, the syntax was rather simple (it does have few more parameters than I’m using, but this was enough for me).

New-SmbShare -Name ShareName -Path X:\SomeFolder\ -FullAccess DOMAIN\UserAcc

In my case, when the disk was already in a correct role I didn’t even need to specify –ScopeName, it automatically added the File Server to correct role. To verify that the newly created share existed I used the following command:

Get-SmbShare -Name SharedFolder

The next thing I did was to verify that the permissions were set ok, this can be done with the following command:

Get-SmbShareAccess -Name ShareName -ScopeName ServerName

get_smbshareaccess

The –ScopeName parameter with SmbShare cmdlets is used to specify the server you’re managing. If the name of the shared folder is unique in the cluster, like in the example above, then you don’t need it.

If you need to add other permissions to shared folder it can be accomplished with the following command:

Grant-SmbShareAccess -Name ShareName -ScopeName ServerName -AccountName DOMAIN\UserAcc -AccessRight Full/Change/Read

So once again Powershell saved the day, also after I figured out the proper cmdlets, creating the actual shared folder and setting permissions was much quicker than doing it through GUI in the first place! And if you need to do it multiple times, like in my example where I had four different cluster groups, it’s even better.

Update on 3.5.2017

When you operate with Windows Failover Cluster resources, such as clustered drives in this case, make sure that you are doing it on the node where they are online. If you try to create the share with the above commands on the node where they are offline, it will not work.

Author: Mika Sutinen

Hi, My name is Mika Sutinen and I'm a Senior Database Administrator for a company called Tieto. I've been working in IT-industry for two decades and I've spend most of my career working with healthcare information systems. I've worked with SQL Server for most of my career, starting with version 6.5 a long, long time ago. My other interests are high availability, everything related to performance (testing, monitoring, etc), Windows operating systems and I'm currently learning more about Azure.

8 thoughts on “Managing shared folders in Windows Failover Cluster with Powershell”

    1. Hi,

      I’m not certain what you mean by masking the shared storage drive letters. You can assign letters to volumes in Windows Failover Clusters, and that is how we usually do it in our environments.

  1. Hi, thank you for the reply. For “masking” I mean that I cannot see nor access directly the cluster file sharing drive letter from Explorer.exe or dos shell. I can see the cluster default share from the cluster console with that letter (eg F:\), when I create a share it correctly maps to F:\shares\ but when I run the powershell command “New-SmbShare -Name ShareName -Path F:\shares\” or “New-SmbShare -Name ShareName -Path F:\”
    I get this error:
    “New-SmbShare : The device or directory does not exist. … (error 2116)”
    Script is running under admin privileges on a cluster Windows 2012 r2 node.
    Thank you again

  2. sorry the wordpress filter cut the correct path into the powershell command. I was writing “F:\shares\new_share” and “F:\new-share”. thank you

  3. Hi,

    That is interesting, for me the command works just fine. F.ex. I just tried that by creating a folder named “test” to a drive (E:) in a cluster, then used this command:

    New-SmbShare -Name ShareTest -Path E:\test

    And it worked just fine. Have you tried starting Powershell Console with the “Run as Administrator” -option (right-clicking it the Powershell icon, then selecting that option)?

  4. I’m running it with administrator privileges (run as..) and it works only on drives which are not under the failover Clustering service. Another thing to say is that you should create ahead the directory you want to configure the share on. In my situation I’m migrating user data folders from simple Windows 2008 shares to a Windows 2012 r2 failover cluster with file sharing role. thank you again, I’ll try to understand better how the cluster manages these shared folders.

  5. I’ve found the solution: I was on a wrong node. As stated elsewhere (see posts here: https://social.technet.microsoft.com/Forums/ie/en-US/b9739ba1-7824-4ffd-85be-a7d3f7cc4fad/clustered-disk-only-showing-on-one-node?forum=winserverClustering): “Normally clustered disks are only accessible by the node where they are online in the cluster. The other node(s) will not have access to the disk.”. So I was trying the code on a node which didnt create the volume…

    1. Thank you for the update, glad you figured it out. That is true, by default resources in Windows Failover Cluster are in shared-nothing model, in which only one node can operate them at any given time.

      I will update my post based on these comments shortly.

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