Cómo cambiar el propietario recursivamente dependiendo del propietario real
Frecuentes
Visto 86 veces
0
I'm just a beginer with PowerShell but I'm already sure that it's a powerfull language. I want to make an easy thing with my first script : "Recursivly changing owner of files and folder depending of the actual owner". But I realize that it will not be as easy as I imagined. One of my problems is that some files or folder name have [brackets].
Aquí está mi guión:
$FolderToScan = "D:\Sauvegardes"
$OldOwner = "BUILTIN\Administrateurs"
$NewOwner = New-Object System.Security.Principal.NTAccount("MON-Domaine","MON-Utilisateur")
$files = Get-ChildItem -LiteralPath $FolderToScan -Recurse
Foreach ($file in $files)
{
$f = Get-Item -LiteralPath $file.FullName
$f = $f.GetAccessControl()
If ($f.Owner -eq $OldOwner) {
$f.SetOwner($NewOwner)
Set-Acl -path $file.FullName -aclObject $f
}
}
What do you thing about it ? Please help.
0 Respuestas
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas powershell file-ownership or haz tu propia pregunta.
What is the problem you are having with file names with brackets? - Lars Truijens
I had a problem with brackets but I think it has been solved with
$f.GetAccessControl()
Actually, I have this error message :Set-Acl the Security Identifier Is Not Allowed to Be the Owner of This Object
with files and folder that matche with the owner I search. - Surfin