none
Set NTFS Permission on multiple folders? RRS feed

  • Question

  • Hi there guys,

    I'm a bit new to Powershell and i'm trying to complete a simple script for a project I'm working on. I get it working 95% of the way but it just not returning the results. I have loaded the NTFSSECURITY Module and I'm using Add-NTFSACCESS to set Deny delete on multiple folders using the paths stored in a .csv file. See below. 

    Script

    $itempath = import-csv "C:\dox\folderpath.csv"

    foreach ($items in  $itempath) {
    Add-NTFSAccess  -path $itempath -AccessRights Delete -Account "domain\username"  -AccessType Deny -AppliesTo ThisFolderOnly
    }

    This is the error i get 

    Add-NTFSAccess : Unable to find the specified file.

    Please help



    • Edited by AlexxusP Wednesday, December 14, 2016 4:54 PM
    • Changed type AlexxusP Wednesday, December 14, 2016 4:54 PM
    Friday, December 2, 2016 5:11 PM

Answers

  • Hi Alex,

    You need to change variable "$itempath" >>>>"$items", and hopefully it contains the correct value...

    foreach ($items in  $itempath) {
    Add-NTFSAccess  -path $items -AccessRights Delete -Account "domain\username"  -AccessType Deny -AppliesTo ThisFolderOnly
    }

    Also have a look here, I think will help you on your issue:

    https://blogs.technet.microsoft.com/heyscriptingguy/2014/11/22/weekend-scripter-use-powershell-to-get-add-and-remove-ntfs-permissions/

    Cheers,

    Sok.

    Wednesday, December 14, 2016 5:24 PM

All replies

  • Edit this:
    Add-NTFSAccess -path $items

    If the CSV file header is Path:

    CSV File Ex:
    Path
    D:\File1
    D:\File2
    D:\File3

    Then it should be like this
    Add-NTFSAccess -path $items.path
    Friday, December 2, 2016 5:16 PM
  • Change type of topic to "Question" by clicking the edit on top of initial post.


    \_(ツ)_/

    Friday, December 2, 2016 5:41 PM
  • Thanks Vincent but as simple as this seems i just cant get it to work. 

    I used this script instead, no CSV....works perfectly.

    $fullpath = Get-ChildItem  "\\Directory_Path\" -Directory | % { $_.FullName}
    Add-NTFSAccess -AccessRights Delete -Account domain\username -Path $fullpath -AccessType Deny -AppliesTo ThisFolderOnly  


    Wednesday, December 14, 2016 4:49 PM
  • Hi Alex,

    You need to change variable "$itempath" >>>>"$items", and hopefully it contains the correct value...

    foreach ($items in  $itempath) {
    Add-NTFSAccess  -path $items -AccessRights Delete -Account "domain\username"  -AccessType Deny -AppliesTo ThisFolderOnly
    }

    Also have a look here, I think will help you on your issue:

    https://blogs.technet.microsoft.com/heyscriptingguy/2014/11/22/weekend-scripter-use-powershell-to-get-add-and-remove-ntfs-permissions/

    Cheers,

    Sok.

    Wednesday, December 14, 2016 5:24 PM
  • Sokratissz Has it yo have the variables wrong I would suggest chaging $itemPath to $ItemPaths and $Items to $Item it may make more sence. also verify that the Paths are getting populated proterly by running the first line from the powershell prompt, you should then have a variable $Item that contains a list of Paths, it it doesn't you'll have trouble.
    Wednesday, December 14, 2016 5:44 PM