windows-server-2008 – Powershell – 克隆整个驱动器的ACL – 错误日志?

前端之家收集整理的这篇文章主要介绍了windows-server-2008 – Powershell – 克隆整个驱动器的ACL – 错误日志?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在将所有数据从AD服务器上的一个(1 TB)卷(非C :)迁移到新的4 TB卷.我已经复制了所有数据,包括FolderRedirection和Profile的东西.

我正在使用一点PowerShell克隆安全ACL.任何人都可以指出我正确的方向如何将输出记录到文件,以便我可以检查它,并确保没有写入失败?

copypermissions.ps1

dir E:\Data -r | where {$_.PSIsContainer} | foreach { 
  $target= ($_.fullname).replace("E:","G:") 
  Get-Acl $_.Fullname | Set-Acl $target 
}

在Set-Acl命令的末尾使用-whatif标志显示它将尝试并执行我想要的操作但是当我实际在测试文件夹上运行它时并不是所有内容都被复制而且我在控制台上出现了一些错误看起来像:

Set-Acl : The security identifier is not allowed to be the owner of
this object.

At E:\copypermissions.ps1:3 char:32
+ Get-Acl $_.Fullname | Set-Acl <<<< $target
+ CategoryInfo : InvalidOperation: (G:\Data\Profiles*USERNAME*:String) [Set-Acl],
InvalidOperationException + FullyQualifiedErrorId :
System.InvalidOperationException,Microsoft.PowerShell.Commands.SetAclCommand

我真的在寻找一个简单的1衬里添加到脚本的末尾,将任何错误写入日志文件.

要将错误重定向到从stederror到常规输出流,请将2> (文件名)在查询的末尾.所以它变成了:
dir E:\Data -r | where {$_.PSIsContainer} | foreach { 
  $target= ($_.fullname).replace("E:","G:") 
  Get-Acl $_.Fullname | Set-Acl $target 
} 2> errors.txt
原文链接:https://www.f2er.com/windows/366224.html

猜你在找的Windows相关文章