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
Categories: PowerShell, Windows Server
What if i would like to do this on multiple servers given by a txt file or something?
Like;
Share folder “D:\Here\andhere\ (folder present on all servers)
Share like mentioned in the article everyone full control, read only acces for users.
LikeLike
What if I wanted to make the shares hidden? Similar to adding the ‘$’ after the share name in the GUI.
LikeLike
Wow great thanks!
LikeLiked by 1 person
You’re welcome
LikeLike