Hi I am trying to add permissions in a file server share folder through csv and PowerShell. I am pretty new on this. The groups are in a different domain. I can change the domain in the gui , like LOCATION option. how do I do it with powershell?

Currently the csv file has the fields:

FolderName;AccountName;AccessRight;Inherited
\ServerName\Folder\subFolder;domain\User1;Modify, Synchronize;True
\ServerName\Folder\subFolder ;domain\user2;FullControl;True
\ServerName\Folder\subFolder ;domain\admin;FullControl;True

And it was with this masterpiece that I destroyed my test environment:

I need a for each loop. and please give me an example.

Thank you!

7 Spice ups

Consider this as well. Let’s say you have DomainA and DomainB. Security groups in either domain are going to have a scope: domain local, global, or universal. If Server is in DomainA and groups are in DomainB, then the groups need to either be global (if users are in DomainB) or universal (if users are in the same forest). DomainA and DomainB need to either be in the same forest or have a trust. Do you meet this criteria?

Yes I made Global Groups. and I need am stuck with this code in PowerShell. can you please solve it?

Yes I made Global Groups. and I need am stuck with this code in PowerShell. can you please solve it? its giving me some error

FolderName Group AccessRight Inherited
C:\Users\GhoshG\Desktop\rrr IR-5-abstract-Modify Read TRUE

Yes I made Global Groups. and I need am stuck with this code in PowerShell. can you please solve it? its giving me some error

FolderName Group AccessRight Inherited
C:\Users\GhoshG\Desktop\rrr IR-5-abstract-Modify Read TRUE

$PermissionList = Import-Csv -Delimiter “;” -Path C:\Users\GhoshG\Desktop\test1.csv

foreach($item in $PermissionList){
$FolderName = $item.FolderName
$AccountName = $item.Group
$AccessRight = $item.AccessRight
$Inherit = $item.Inherited

Get-Item $FolderName | Add-NTFSAccess -Account $AccountName -AccessRights $AccessRight

}

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
‘PSGallery’?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “N”): a
Get-Item:
Line |
12 | Get-Item $FolderName | Add-NTFSAccess -Account $AccountName -Acce …
| ~~~~~~~~~~~
| Cannot bind argument to parameter ‘Path’ because it is null.

$FolderName is empty

Ensure that your CSV has a column named “FolderName” and that it doesn’t contain any blanks or white space

-LiteralPath didn’t work. Please help me solve it.

FolderName Group AccessRight Inherited
C:\Users\GhoshG\Desktop\rrr IR-5-abstract-Modify Read TRUE

and this is a example of my code and CSV

$PermissionList = Import-Csv -Delimiter “;” -Path C:\Users\GhoshG\Desktop\test1.csv

foreach($item in $PermissionList){
$FolderName = $item.FolderName
$AccountName = $item.Group
$AccessRight = $item.AccessRight
$Inherit = $item.Inherited

Get-Item -LiteralPath $FolderName | Add-NTFSAccess -Account $AccountName -AccessRights $AccessRight

}
Get-Item:
Line |
11 | Get-Item -LiteralPath $FolderName | Add-NTFSAccess -Account $Acco …
| ~~~~~~~~~~~
| Cannot bind argument to parameter ‘LiteralPath’ because it is null.

$FolderName is still empty. Can you post the first few lines of the CSV (including the header) so we can see what it looks like? Either FolderName isn’t a value in the csv or one of the line items is blank in the FolderName column.

This is my new code It worked on my personal pc but it is not working in the server. I am trying to add this to the server.

Name Path Group AccessRight Inherited count
rrr \FS5\F:\rrr FS5-Administration-Modify ReadAndExecute,Synchronize TRUE 1
rrr \FS5\F:\rrr FS5-123-Modify ReadAndExecute,Synchronize TRUE 2
rrr \FS5\F:\rrr FS5-users-Modify ReadAndExecute,Synchronize TRUE 3

foreach($item in $PermissionList){
$FolderName = $item.FolderName
$Path = $item.Path
$AccountName = $item.Group
$AccessRight = $item.AccessRight
$Inherit = $item.Inherited

Get-Item $FolderName -Path $Path | Add-NTFSAccess -Account $AccountName -AccessRights $AccessRight
Write-Host -ForegroundColor Green “Folder $($item.count)!”
}

it dosent work and dosent even give me any error.

and the groups are in a different domain. its a global group. I have tried Domain\group format but it doesn’t work.

Looks like you need to use $item.Name instead of $item.FolderName

Name 	Path 	   Group 	         AccessRight 	       Inherited 	count 	
rrr 	\\FS5\F:\rrr FS5-Administration-Modify ReadAndExecute,Synchronize  TRUE 	1

You can see this in your text. Name, Path,AccessRight, Inherited, and Count are valid properties. When pasting anything please use the </> at the top of the editor box so that it’s legible, This includes text and code.

I don’t understand what is missing? I am still getting errors. Can you please fix the code?

Name Group AccessRight Inherited count
\FS5\F:\rrr FS5-Administration-Modify ReadAndExecute,Synchronize TRUE 1
\FS5\F:\rrr FS5-123-Modify ReadAndExecute,Synchronize TRUE 2
\FS5\F:\rrr FS5-users-Modify ReadAndExecute,Synchronize TRUE 3

PS C:\Users***> $PermissionList = Import-Csv -Delimiter “;” -Path ‘C:\Users\GhoshG\Desktop\test1.csv’

foreach($item in $PermissionList){
$FolderName = $item.Name
$AccountName = $item.Group
$AccessRight = $item.AccessRight
$Inherit = $item.Inherited

Get-Item -LiteralPath $FolderName | Add-NTFSAccess -Account $AccountName -AccessRights $AccessRight
Write-Host -ForegroundColor Green “Folder $($item.count)!”
}

Get-Item:
Line |
10 | Get-Item -LiteralPath $FolderName | Add-NTFSAccess -Account $Acc …
| ~~~~~~~~~~~
| Cannot bind argument to parameter ‘LiteralPath’ because it is null.
Folder 1!
Get-Item:
Line |
10 | Get-Item -LiteralPath $FolderName | Add-NTFSAccess -Account $Acc …
| ~~~~~~~~~~~
| Cannot bind argument to parameter ‘LiteralPath’ because it is null.
Folder 1!
Get-Item:
Line |
10 | Get-Item -LiteralPath $FolderName | Add-NTFSAccess -Account $Acc …
| ~~~~~~~~~~~
| Cannot bind argument to parameter ‘LiteralPath’ because it is null.
Folder 1!
Get-Item:
Line |
10 | Get-Item -LiteralPath $FolderName | Add-NTFSAccess -Account $Acc …
| ~~~~~~~~~~~
| Cannot bind argument to parameter ‘LiteralPath’ because it is null.
Folder 1!
Get-Item:
Line |
10 | Get-Item -LiteralPath $FolderName | Add-NTFSAccess -Account $Acc …
| ~~~~~~~~~~~
| Cannot bind argument to parameter ‘LiteralPath’ because it is null.
Folder 1!

We’re not a script writing service. I’ve given plenty of advice on what to look at and change. I’ve also asked that you use </> to paste data. I’m not sure how to further assist if you’re going to ignore what I’m recommending/asking.