Cómo cambiar el propietario recursivamente dependiendo del propietario real

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) {
        Set-Acl -path $file.FullName -aclObject $f

What do you thing about it ? Please help.

preguntado el 09 de septiembre de 13 a las 21:09

What is the problem you are having with file names with brackets? -

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. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.