PowerShell – set ACL

#-------------[deklarations]--------------------------
#source

#logs
$successLog='\\hostname\logs\dirs-done.LOG'
$errorLog='\\hostname\logs\dirs-error.LOG'
$unreachableLog='\\hostname\logs\dirs-unreachable.LOG'
$reportLog='\\hostname\logs\dirs-report.txt'
#params
$dirToCheck='\\fs\home\'
#-------------[functions]--------------------------

$departmentsHomes = Get-ChildItem -Path $dirToCheck

foreach($departmentHome in $departmentsHomes) {
    $departmentHomePath = $dirToCheck + "\" + $departmentHome
    $userHomes = Get-ChildItem -Path $departmentHomePath

    foreach($userHome in $userHomes) {
        $userHomePath = $dirToCheck + $departmentHome + "\" + $userHome
        $userDocuments = Get-ChildItem -Path $userHomePath

        foreach($userDocument in $userDocuments) {

            if($userDocument.ToString() -eq "Desktop") {
                $userDesktopPath = $userHomePath + '\Desktop'
                    $acl = $null;
                    $acl = Get-Acl -Path $userHomePath
                    Set-Acl -Path $userDesktopPath -AclObject $acl
            }
        }
    }
}
#-------------krolaki.eu--------------------------

Leave a Reply

Your email address will not be published. Required fields are marked *