Solved

PowerShell Set-Acl recursively

Posted on 2014-03-05
2
4,396 Views
Last Modified: 2014-03-06
Hi,

I have the below script, works fine but when setting the ACL it only set's the ACL on the root folder and doesn't propagate down. How can I get it to set the ACL to all files and folders?

1) imports folder names from folderlist.txt
2) gets fqdn and serve rip info from input.csv
3) copies folders from 1 server location to another server location
4) copies acl per folder from location 1 and set's the acl per folder on location 2

This works great, but I need the permissions to propagate down on location 2.

Thank you.

gc folderlist.txt | % {
$user = "$_"
Import-Csv "C:\TEMP\Favorites\input.csv" | ForEach {
If ($_.FQDN -eq $env:USERDNSDOMAIN) { $file_server = $_.'Server IP' } 
}
if (Test-Path -Path "\\$file_server\profiles$\$user\Favorites")
{
copy-item -path  \\$file_server\profiles$\$user\Favorites -destination \\$file_server\userhome$\$user\Favorites -recurse -force 
copy-item -path  "\\$file_server\profiles$\$user\Application Data\Microsoft\Signatures" -destination \\$file_server\userhome$\$user\AppData\Roaming\Microsoft\Signatures\ -recurse -force -ErrorAction SilentlyContinue
Get-Acl -path \\$file_server\profiles$\$user\Favorites\ | Set-ACL -path \\$file_server\userhome$\$user\Favorites\
Get-Acl -path  "\\$file_server\profiles$\$user\Application Data\Microsoft\Signatures\" | Set-Acl \\$file_server\userhome$\$user\AppData\
remove-item -path  \\$file_server\profiles$\$user -recurse -force
}                                            
}

Open in new window

0
Comment
Question by:levertm
2 Comments
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
Comment Utility
$NewAcl = Get-Acl File0.txt
Get-ChildItem c:\temp -Recurse  -Force | Set-Acl -AclObject $NewAcl

Open in new window

   
from powershell help set-acl -examples
0
 

Author Comment

by:levertm
Comment Utility
Hi David,

I tried your suggestion, it works. Thank you.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
View Security Group Permisssions 6 13
Linux Scripting 3 39
Folder NTFS Permissions 14 66
GPO warning 15 23
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article will help you understand what HashTables are and how to use them in PowerShell.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now