I'm seeking assistance with a PowerShell script designed to manage permissions on a network share folder. The goal is to grant domain users (in the format domainname\domain users) specific permissions for a network share folder, allowing them to perform actions like write, list folder contents, read & execute, and modify (without granting full control). Additionally, I would like the script to automatically skip files that are currently in use or locked.
I have already tried the following script, but it resulted in empty permissions:
Install-Module NTFSSecurity -Scope CurrentUser
Set-ExecutionPolicy RemoteSigned
# Define the folder path and username
$username = "Domain_Name\user"
$folderPath = "\\Network_Share\Software"
# Get the current ACL of the folder
$acl = Get-Acl $folderPath
# Create a new access rule to grant "Read" and "Write" permissions to the user
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($username, "Read,Write", "Allow")
# Add the access rule to the ACL
$acl.AddAccessRule($accessRule)
# Set the modified ACL back to the folder
Set-Acl -Path $folderPath -AclObject $acl
Write-Output "Read and Write permissions granted to $username for folder $folderPath"
However, this script did not successfully grant the intended permissions. I suspect there might be an issue with handling permissions on network shares or potential conflicts with in-use files.
Could someone provide an improved PowerShell script or suggestions on how to correctly set permissions on a network share folder while ensuring that in-use files are handled appropriately?
Your assistance is greatly appreciated!