function New-ShareWithPerms { [cmdletbinding()] param ( [parameter(ValueFromPipelineByPropertyName)] [string]$Name, [parameter(ValueFromPipelineByPropertyName)] [string]$FullName, [string]$Groups ) Process { $acl = Get-Acl -Path $_.FullName $groupRW = $Groups + $_.Name + "_RW" $groupR = $Groups + $_.Name + "_R" $aceRW = New-Object System.Security.AccessControl.FileSystemAccessRule($groupRW, 'Modify,Synchronize,DeleteSubdirectoriesAndFiles', 'ContainerInherit,ObjectInherit', 'None', 'Allow') $aceR = New-Object System.Security.AccessControl.FileSystemAccessRule($groupR, 'ReadAndExecute', 'ContainerInherit,ObjectInherit', 'None', 'Allow') $acl.AddAccessRule($aceRW) $acl.AddAccessRule($aceR) Set-Acl $_.FullName -AclObject $acl New-SmbShare -Name $_.Name -Path $_.FullName -FullAccess Everyone -CachingMode None } } $groupTemplate = "domain\Share_" Get-ChildItem $SharePath | New-ShareWithPerms -Groups $groupTemplate |