更改所有权和转移访问权利时的错误
我遇到了一个问题,写了一个脚本,该脚本通过程序来压缩PDF文件,并通过复制旧文件以区分对新文件的访问来将权利转移到新文件中。 这是我拥有的代码的一部分,
$owner = $origFile.GetAccessControl().GetOwner([System.Security.Principal.SecurityIdentifier])
$newFile = Get-Item -Path $PathoutFile
$FileSecurity = new-object System.Security.AccessControl.FileSecurity
$FileSecurity.SetOwner($owner)
[System.IO.File]::SetAccessControl($newFile, $FileSecurity)
Get-Acl -Path $origFile | Set-Acl -Path $newFile
我的问题是: 我使用域管理员特权执行脚本,一切正常。如果我使用域用户帐户并授予目录的最大权利,则保存一个压缩文件,在这种情况下,我会发现错误“尝试执行未经授权的操作。 我不想出于简单原因在管理员帐户下运行脚本,我相信此操作是多余的。我的判断可能不正确,请帮助解决此问题。 PS操作是在网络目录上执行的。 提前致谢。
I ran into a problem, wrote a script that compresses pdf files through a program and transfers rights to a new file by copying from the old one to differentiate access to new files.
Here is the part of the code that I have is the problem
$owner = $origFile.GetAccessControl().GetOwner([System.Security.Principal.SecurityIdentifier])
$newFile = Get-Item -Path $PathoutFile
$FileSecurity = new-object System.Security.AccessControl.FileSecurity
$FileSecurity.SetOwner($owner)
[System.IO.File]::SetAccessControl($newFile, $FileSecurity)
Get-Acl -Path $origFile | Set-Acl -Path $newFile
My problem is this:
I execute the script using domain administrator privileges, everything works fine. If I use a domain user account and grant maximum rights to the directory, a compressed file is saved in it, and in this case I get the error “Attempt to perform an unauthorized operation.
I do not want to run the script under the administrator account for a simple reason, I believe that such rights are redundant for this operation. My judgments may not be correct, please help in solving this problem.
P.s actions are performed on a network directory.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我本人使用NTFSSecurity PowerShell模块找到了解决主要问题的解决方案。
使用get-ntfsaccess $ filein进行访问权限的转移| add-ntfsaccess $ fileout
I myself found a solution to my main problem using the NTFSSecurity PowerShell module.
The transfer of access rights was performed using the Get-NTFSAccess $filein | Add-NTFSAccess $fileout