Reputation: 21
I am trying to apply permissions to multiple folders at once. I have a .csv file with the folder paths in one column and the security groups in a second column. Most folders will have multiple groups with access. The .csv is in the following format:
folderpath groupname
---------- ---------
C:\Folder1 Group1
C:\Folder2 Group2, Group3
My code will not currently apply the permissions because there are multiple values in some groupname cells. It will apply if only one group is listed.
#Specify CSV location
$csv = import-csv G:\testcsv.csv
#Start loop
foreach($masterlist in $csv)
{
$folderpath = $masterlist.folderpath
$groupname = $masterlist.groupname
#Apply permission to folderpath
add-ntfsaccess -path $folderpath -account $groupname -accessrights modify,synchronize
}
For example, if I run the above code, Group1 will successfully be given permission to C:\Folder1. But C:\Folder2 will have nothing applied because Group2 and Group3 are both in the same cell. Can I adjust my code without having to manually separate hundreds of these cells in the .csv?
Thank you for your help!!!!!
Upvotes: 2
Views: 4075
Reputation: 111
just create inside loop foreach Group :) simplest method
#Start loop
foreach($masterlist in $csv)
{
$folderpath = $masterlist.folderpath
$groupnames = $masterlist.groupname -split ","
foreach ($group in $groupnames ) {
#Apply permission to folderpath
add-ntfsaccess -path $folderpath -account $group -accessrights modify,synchronize
}
}
this is adHoc response but i think you get the idea.
Upvotes: 1