I am trying to change permissions on a file through Powershell, and am having trouble figuring out how to get this to work.
$path1 = "\\somepath1\somefile1"
$path2 = "\\somepath2\somefile2"
$acl = Get-Acl $path1
$access_rule = New-Object System.Security.AccessControl.FileSystemAccessRule("User","Write","ContainerInherit,ObjectInherit","None","Deny")
$acl.SetAccessRule($access_rule)
$acl | Set-Acl $path2
"User"
is a specified usergroup, of many users, and is called something different in the actual code. This throws two errors:
Exception calling "SetAccessRule" with "1" argument(s): Some or all identity references could not be translated."
Set-Acl : Some or all identity references could not be translated.
Then, I try to dumb the code down, essentially trying to copy permissions of one file to another:
$path1 = "\\somepath1\somefile1"
$path2 = "\\somepath2\somefile2"
Get-Acl -Path $path1 | Set-Acl -Path $path2
Even this throws an error:
Set-Acl : Some or all identity references could not be translated.
If I understand these errors correctly, then my "User"
is not being properly defined. I try to get the "User"
info by running the Get-ADUser
cmdlet, but the ActiveDirectory module must not be installed, because I receive this error:
Get-ADUser : The term 'Get-AdUser' is not recognized as the name of a cmdlet,.........
My main question now, is how can I get the user SID information to properly change the permissions on the file? Am I missing a step somewhere? Is there a better way to change file permissions? Can I even try to change permissions for a group? I have hit a wall trying to find a solution, lol.
I have looked at the following sources for help: