Author Posts

November 25, 2014 at 4:07 pm

Hi there.

Im a very very noob on Powershell and im trying to create a share and i´m stuck on add a user to the share.

Here is my script:

$user= Read-Host -Prompt User
$FolderPath = "c:\$user"

$Shares=[WMICLASS]'WIN32_Share'

$ShareName="$user$"

New-Item -type directory -Path $FolderPath

$Shares.Create($FolderPath,$ShareName,0)

$Acl = Get-Acl $FolderPath
$Acl.SetAccessRuleProtection($True, $False)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule('Administrators','FullControl','ContainerInherit, ObjectInherit', 'None', 'Allow')
$Acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule('Teste','Modify, Synchronize', "ContainerInherit, ObjectInherit", "None", "Allow")
$Acl.AddAccessRule($rule)

Get-Acl $FolderPath | Format-List
Set-Acl $FolderPath $Acl

November 26, 2014 at 7:31 pm

Hi João,

I dont have a domain joined system nearby to test, but was able to achieve this on my workstation using the code below. Can you try this and let me know how you get on?

$user= Read-Host -Prompt User
$FolderPath = "c:\$user"

$Shares=[WMICLASS]'WIN32_Share'

$ShareName="$user$"

New-Item -type directory -Path $FolderPath

$Shares.Create($FolderPath,$ShareName,0)

$Acl = Get-Acl $FolderPath
$Acl.SetAccessRuleProtection($True, $False)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule('Administrators','FullControl','ContainerInherit, ObjectInherit', 'None', 'Allow')
$Acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($user,'Modify, Synchronize', "ContainerInherit, ObjectInherit", "None", "Allow")
$Acl.AddAccessRule($rule)

Get-Acl $FolderPath | Format-List
Set-Acl $FolderPath $Acl

November 27, 2014 at 4:45 am

Hi Tim.

I tested on my workstation and it worked!

But apparently the script was fine? I cant see any changes beside the variable $user on line16

Thanks again