我期待着将数千份档案和文件的所有权从一个特定用户改为另一个用户。
在文件夹结构内,大多数档案和文件夹都需要将其所有权从用户A改为用户B,但用户委员会拥有的一些文件需要留下来。
I had found a previous question which seemed to be asking the same as this, but I can no longer find it to reference. It did give the below though.
$FolderToScan = "G:FolderFolderFolder"
$OldOwner = "DomainUser"
$NewOwner = New-Object System.Security.Principal.NTAccount("Domain","User")
$files = Get-ChildItem -LiteralPath $FolderToScan -Recurse
Foreach ($file in $files)
{
$f = Get-Item -LiteralPath $file.FullName
$f = $f.GetAccessControl( Access )
If ($f.Owner -eq $OldOwner) {
$f.SetOwner($NewOwner)
Set-Acl -path $file.FullName -aclObject $f
}
}
When I run the above with the correct details in place of domain/user, nothing happens.
如果任何人能够把我引向正确的方向,那将是巨大的。