File Server : Set File Sharing (Advanced)


Set Network File and Folder Sharing. <br>On this example, Configure a sharing folder [D:\Share01] that only users that are in [DevGroup01] group can read and write.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

# create a group
PS C:\Users\Administrator New-LocalGroup -Name "DevGroup01"

Name Description
---- -----------
DevGroup01

# add a user to the group
PS C:\Users\Administrator Add-LocalGroupMember -Group "DevGroup01" -Member "Serverworld"

# create a folder for sharing
PS C:\Users\Administrator mkdir D:\Share01

Directory: D:\

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 9/17/2019 7:20 PM Share01

# set sharing
# -Name [share name you like]
# -Path [path of shared folder]
# -FullAccess [users or groups that is granted full-control permission]
PS C:\Users\Administrator New-SmbShare -Name "Share01" -Path "D:\Share01" -FullAccess "DevGroup01"

Name ScopeName Path Description
---- --------- ---- -----------
Share01 * D:\Share01

# grant NTFS permission
PS C:\Users\Administrator icacls "D:\Share01" /grant "DevGroup01:(OI)(CI)(F)"
processed file: D:\Share01
Successfully processed 1 files; Failed processing 0 files

# confirm settings
PS C:\Users\Administrator icacls "D:\Share01"
D:\Share01 BUILTIN\Administrators:(F)
RX-8\DevGroup01:(OI)(CI)(F)
BUILTIN\Administrators:(I)(OI)(CI)(F)
NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
CREATOR OWNER:(I)(OI)(CI)(IO)(F)
BUILTIN\Users:(I)(OI)(CI)(RX)
BUILTIN\Users:(I)(CI)(AD)
BUILTIN\Users:(I)(CI)(WD)

Successfully processed 1 files; Failed processing 0 files

# remove unnecessary permissions
# disable inheritance first
PS C:\Users\Administrator icacls "D:\Share01" /inheritance:d
processed file: D:\Share01
Successfully processed 1 files; Failed processing 0 files

# remove unnecessary permissions (example blow, remove Users persmissions all)
PS C:\Users\Administrator icacls "D:\Share01" /remove "Users"
processed file: D:\Share01
Successfully processed 1 files; Failed processing 0 files

# confirm settings
PS C:\Users\Administrator icacls "D:\Share01"
D:\Share01 BUILTIN\Administrators:(F)
RX-8\DevGroup01:(OI)(CI)(F)
BUILTIN\Administrators:(OI)(CI)(F)
NT AUTHORITY\SYSTEM:(OI)(CI)(F)
CREATOR OWNER:(OI)(CI)(IO)(F)

Successfully processed 1 files; Failed processing 0 files

124 Views