I have CSV file where I have name and folder path. I want to provide file permission to each name and the folder path.
I am using the following code
$mt = Import-Csv “C:\Users\shaker\Desktop\access.csv” |
ForEach-Object {Get-Acl -Path $_.file}
$Accessrule = Import-Csv “C:\Users\shaker\Desktop\access.csv” |
ForEach-Object {New-Object System.Security.AccessControl.FileSystemAccessRule ($_.name,"FullControl","Allow")}
ForEach-Object {$mt.SetAccessRule($AccessRule)}
But I am getting some error
PS C:\Users\shaker> C:\Users\shaker\Desktop\f1.ps1 Cannot convert argument "rule", with value: "System.Object[]", for "SetAccessRule" to type "System.Security.AccessControl.FileSystemAccessRule": "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Security.AccessControl.FileSystemAccessRule"." At C:\Users\shaker\Desktop\f1.ps1:6 char:17 + ForEach-Object {$mt.SetAccessRule($AccessRule)} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument