Reputation: 1349
Can I set the owner and the security group for a file using Powershell?
I mean, can I change for example CVWINSERV1\None
to BUILTIN\Administrators
?
Path : Microsoft.PowerShell.Core\FileSystem::C:\dev\lpeg.dll
Owner : BUILTIN\Administrators
Group : CVWINSERV1\None
Access : NT AUTHORITY\SYSTEM Allow FullControl
BUILTIN\Administrators Allow FullControl
BUILTIN\Users Allow ReadAndExecute, Synchronize
Audit :
Sddl : O:BAG:S-1-5-21-704654959-829129038-1184563323-513D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)
The whole scenario is this: I copy the file in Windows explorer under my account. After that, in my app (using Tomcat which runs under another account) I copy the file to the new destination folder, set the permissions and the owner. The permissions are set without a problem, as wel as the owner user, but I can not change the domain (?) of the owner. I thought it is sort of a symbolic link but it doesn't change at all.
Upvotes: 0
Views: 4014
Reputation: 175085
Use Get-Acl
to retrieve the ACL, then call the SetGroup()
method to set the group:
$ACL = Get-Acl .\path\to\file
$Admins = New-Object System.Security.Principal.NTAccount 'BUILTIN\Administrators'
$ACL.SetGroup($Admins)
$ACL |Set-Acl .\path\to\file
Upvotes: 3