
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Share a Windows Folder Using PowerShell
To share a windows folder using PowerShell, we can use the New-SmbShare command. This command is a part of the module SmbShare.
In this example, we have a folder called “DSC” and we want to share. The below command will simply share folder
New-SmbShare -Path E:\DSC\ -Name "Shared Folder"
Output
Name ScopeName Path Description ---- --------- ---- ----------- Shared Folder * E:\DSC
DSC folder will be shared with a “Shared Folder” name with everyone’s Read Permission by default because we haven’t specified the scope yet.
To assign the Full Access permission to the specific user, we can use the -FullAccess parameter followed by active directory username to provide the full access. For example,
New-SmbShare -Name "Shared Folder" -Path "E:\DSC\" -FullAccess "automationlab\delta","Automationlab\Beta"
Full access will be provided to Delta and Beta users of the domain AutomationLab.
Similarly, for only read-only permission we can use the -Readonly parameter.
For Change and Read permission use -ChangeAccess Parameter.
To provide multiple permissions,
New-SmbShare -Name "Shared Folder" -Path "E:\DSC\" -ChangeAccess "Automationlab\Beta" -FullAccess "AutomationLab\Delta"
The above example will provide Change Access to a Beta AD user and Full Access to a Delta AD user.
To create an encrypted shared folder, you can use -Encrypted parameter. For example,
New-SmbShare-Name"Shared Folder"-Path "E:\DSC\"-EncryptData $true