Creating multiple SMB Shares at once (Bulk) with PowerShell

So you are about to provide a new file server. Several folder shares have to be created. If you don’t want to point and click inside the graphical interface, you might consider creating file shares with a Powershell One-Liner. Here is a how-to for you. Credits to my students group IT-T29 who gave me the inspiration for automating file share creation. The student group is pretty lazy and want to automate everything with PowerShell 😉

It’s assumed that you want to follow Microsofts SMB share recommodations and grant everyone full access share permissions. You then further want to restrict your users by using NTFS permissions.

First, you have to grab the folders you want to share. In the following example all forders are located in C:\Temp. Have a look.


Now let’s do some magic stuff, namely creating 4 or millions 😉 of file shares at once. The default share permissions will be modified to Everyone: Full Control. I also provide a description “Test” for all newly created file shares. More about the description parameter later.

Open PowerShell ISE (ise.exe). Hit the keys.

Get-ChildItem -Path C:\Temp\ -Directory | ForEach-Object {New-SmbShare -Name $_.Name -Path $_.Fullname -FullAccess Everyone -Description Test}


Boom. Mission accomplished.

If you want to undo that, just bring your share description “Test” into play. The following command will stop sharing on all “Test” SMB shares.

Get-SmbShare | Where-Object Description -EQ 'Test' | Remove-SmbShare

Have a nice week!

More about file shares here: PowerShell: How to create File Shares

5 replies »

  1. What if i would like to do this on multiple servers given by a txt file or something?
    Share folder “D:\Here\andhere\ (folder present on all servers)

    Share like mentioned in the article everyone full control, read only acces for users.


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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.