我有这个脚本
$dir = '\\knesmbmdc001\profiles'
$logFile = 'C:\user_done.txt'
Get-ChildItem -Directory $dir | % {
$user = $_.Name
$acl = Get-Acl –LiteralPath $_.FullName
$userIdentity = New-Object System.Security.Principal.NTAccount $user
$acl.SetOwner($userIdentity)
Set-Acl –LiteralPath $_.FullName -AclObject $acl
Add-Content $logFile $user
}
我收到此错误
Exception calling "SetOwner" with "1" argument(s): "Some or all identity references could not be translated."
Set-Acl : The security identifier is not allowed to be the owner of this object.
我正在尝试获取文件夹的名称(用户名)并将其设置为所有者。
答案 0 :(得分:0)
该文件夹的名称不是有效的用户名。您应该在脚本中输出$user
以查看哪个失败。我假设这是Windows域的漫游配置文件。我看到两个潜在的问题:
username.v2
。所以你需要从中提取名称。如果(因为-eq 2),请尝试:
$user = $_.Name.Split(".")[0]