File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -77,12 +77,28 @@ if ($existingShare) {
7777 # Create the share. Deny access to "Everyone" otherwise it will be accessible by default.
7878 Write-Output " Sharing the folder '$folderPath ' as '$shareName '. without any user permissions."
7979 New-SmbShare - Name $shareName - Path $folderPath - NoAccess " Everyone"
80+ # Define variables
81+ $ShareName = " NewShare"
82+ $SharePath = " C:\Path\To\Share"
8083
84+ # Create the folder if it doesn't exist
85+ if (-Not (Test-Path $SharePath )) {
86+ New-Item - ItemType Directory - Path $SharePath - Force
87+ }
88+
89+ # Create the share
90+ New-SmbShare - Name $ShareName - Path $SharePath - Description " A restricted share with no default access" - FullAccess " "
91+
92+ # Remove "Everyone" access
93+ Revoke-SmbShareAccess - Name $ShareName - AccountName " Everyone"
94+
95+ # Verify permissions
96+ Get-SmbShareAccess - Name $ShareName
8197 # Grant the user read and write access to the share
8298 Write-Output " Granting read and write access to user '$username ' for share '$shareName '."
8399 Grant-SmbShareAccess - Name $shareName - AccountName $username - AccessRight Change - Confirm:$false
84100}
85101
86102# Prevent the window from closing after the program ends
87103Write-Host " Press any key to close this window..."
88- [void ][System.Console ]::ReadKey()
104+ [void ][System.Console ]::ReadKey()
You can’t perform that action at this time.
0 commit comments