troubleshooting Question

Nested ForEach in Powershell

Avatar of Itxx
Itxx asked on
Powershell* NTFS
4 Comments2 Solutions2321 ViewsLast Modified:
Hi all,

I'm trying this relative simple script but I think I'm not using the break function right.

First, I need to iterate through list 1(pathlist.txt). For every object in list 1, I need to iterate through list2 (hvservers.txt) and apply NTFS permissions to the paths from list1 and add the accounts from list2.

The script goes like this:
Import-Module NTFSSecurity

$pathlist = Get-Content 'C:\itxx\hvfolderpermissions\pathlist.txt'
$hvlist = Get-Content 'C:\itxx\hvfolderpermissions\hvservers.txt'


ForEach ($Path In $pathlist) {
:next

ForEach ($HVserver In $hvlist) {

Add-NTFSAccess -Path $Path -account $HVserver -AccessRights FullControl

break:next


}

}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros