Set-ACL - Method Failed with error code 1337

Hello everyone,

I am writing a code that searches through our folders and finds home drives and profiles that do not have a corresponding AD object and delete them, i.e. for people that have left and their profile was never deleted. I am using the following script to run against one user and I keep getting the errors : Method Failed with error code 1337.

this is underlined in RED for the error: Set-acl -path "$Folderpath" -aclobject $currentACL

Error: the data area passed to the system is too small

this is underlined in RED for the error: Takeown.exe /f "$folderpath" /R /D Y /A

 

Function Get-ACLError($Folder){

$Error.clear()

$Errorarray = @()

get-childitem "$Folder" -Recurse -erroraction silentlycontinue | select Fullname

     IF($error){

      $errorarray = $error + $errorarray

       foreach($err in $errorarray){

        if($err.fullyqualifiedErrorID -eq "DirUnathorizedAccessError,Microsoft.Powershell.Command.Getchilditem"){

         Write-host "Unable to Access $Err.TargetObject" -foregroundcolor yellow

            Take-ownership($err.TargetObject)

            Get-ACLError($err.TargetObject)

          }

        }

      }

  }

 

Function Take-Ownership{

     param(

     [string]$folderpath

     )

     Takeown.exe /F "$folderpath" /R /D Y /A

     $currentACL + Get-ACL "$folderPath"

     Write-host "..Adding Admin to $Folderpath" -fourgroundcolor yellow

     $systemACLPermissions = "Administrator","Fullcontrol","containerinherit,objectinherit","none","allow"

     $systemaccessrule = new-object system.security.accesscontrol.filesystemaccessrule $systemACLPermission

     $currentACL.addaccessrule($systemaccessrule)

     write-host "..adding Infrastructure to "Folderpath" -fourgroundcolor yellow

     $adminACLPermission = "mydomain","fullcontrol",containerinherit,objectinherit","none","allow"

     $systemaccessrule = new-object system.security.accesscontrol.filesystemaccessrule $adminACLPermission

     $currentACL.addaccessrule($systemaccessrule)

     Set-ACL -path "$Folderpath" -Aclobject $currentACL

}

 Take-ownership "XXXX\home\(SID)" -recurse |get-aclerror; remove-item "XXXX\home\(SID)"

Any help would be appreciated.




  • Edited by Richardlaw Wednesday, August 26, 2015 4:22 PM
August 26th, 2015 4:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics