Skip to content

Commit 2c606a6

Browse files
authored
Update create-user-and-share.ps1
1 parent caa613a commit 2c606a6

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

create-user-and-share.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff 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
87103
Write-Host "Press any key to close this window..."
88-
[void][System.Console]::ReadKey()
104+
[void][System.Console]::ReadKey()

0 commit comments

Comments
 (0)