How to create a Shared Folder using PowerShell
In this post, I want to show how to create a shared folder using PowerShell. To do this, we can first check the PowerShell help to know the parameters of the New-SmbShare cmdlet To check the PowerShell help, we will use the Get-Help command with the following syntax. To create a new share with PowerShell, use the New-SmbShare cmdlet with the following syntax:
New-SmbShare `
-Name <String> `
-Path <String> `
-FullAccess <String[]> `
-ChangeAccess <String[]> `
-ReadAccess <String[]> `
-Description <String>
In the case of a new directory, we create it with the New-Item cmdlet, run the PowerShell console as administrator, and then type:
New-Item `
-Path 'c:\Parent-Directory\Sub-Directory' `
-ItemType Directory
Now, I can turn it into a shared folder using the New-SMBShare cmdlet. Run the PowerShell console as administrator, and then type:
New-SMBShare `
–Name SharedFolder `
–Path 'C:\Parent-Directory' `
–FullAccess Administrators `
-ChangeAccess 'Server Operators' `
-ReadAccess Users
As you can see in the Screenshot, using the Get-SmbShare cmdlet we can check the shared directories.
If you want to know more about the New-SmbShare cmdlet, check out this link.