Saturday, May 23, 2015

Creating a file share using PowerShell

I am always looking for easier ways to automate operations that I perform routinely and one of the things that I always have to do when I am setting it up servers is to create file shares.

Well, in the past, I have always used the net share command, but since this does not always work reliably, I was hoping for a better way to accomplish this using PowerShell.

Fortunately, I found this article which describes just that!!

http://blogs.technet.com/b/heyscriptingguy/archive/2014/01/09/powertip-use-powershell-to-create-new-shared-folder.aspx

Of course, I wanted to modify this script to suit my needs, so I modified it in the following manner based on the following TechNet article: https://technet.microsoft.com/en-us/library/jj635722%28v=wps.630%29.aspx

$FileSharePath = "C:\MyShare"
$FileShareName = "MyShare"
$UserGroups = "Administrators"
$ComputerName = $env:COMPUTERNAME
 
Clear-Host
$ShareAccess = ".\$UserGroups"
New-SmbShare -Name $FileShareName -Path $FileSharePath -FullAccess $ShareAccess -Confirm:$false


No comments:

Post a Comment