Script to check option Include inheritable permission from this object’s parent” if this option is unchecked

Hello,
I am looking for a script to check the "Include inheritable permission from this object’s parent” option on the folders that I specify in the spreadsheet.


Let me know if it is possible.

Please help.

Thank you very much!
creative555Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
Surprised no one has answered this yet... As it is pretty straightforward. See script below...
Make sure that your CSV file has a column head of PATH and all of the required paths to check below.

$Input = Import-Csv "c:\filename.csv"

ForEach ($Item in $Input)
    {

        $Check = Get-Item -Path $Item.Path | Get-Acl

            If ($Check.Access.IsInherited -eq "True") 
                {

                Write-Output "$Item is Inherited"

                }

            else
                {

                Write-Warning "$Item is not Inherited"

                }


}

Open in new window


Will.
Jason CrawfordTransport NinjaCommented:
I think by 'check' the OP means 'enable inheritance'.  Try this on some test files and see if it works for you (adding on to Will's script):

$Input = Import-Csv 'c:\filename.csv'

ForEach ($Item in $Input) {
    $Check = Get-Item -Path $Item.Path | Get-Acl
    If ($Check.Access.IsInherited -eq 'True') {
        Write-Host "Inheritance is enabled for $Input"
    }
    else {
       Write-Host "Enabling inheritance for $Item"
       (Get-ChildItem $Input).GetAccessControl().SetAccessRuleProtection($true,$true)
    }
}

Open in new window

creative555Author Commented:
Oh. Excellent!! Thank you so much. So, the first script will check if the checkbox is set and then other script will set that checkbox. Right? If yes, then this is exactly what I need. testing now.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

creative555Author Commented:
I am getting this error when trying to enable the option Include inheritable permission with the second script. here is the error I get. It didn't enable the option:
FYI I checked the path to the share and it is correct - \\server01\TestShare3.

I am running the script from directory E:\scripts\NTFS\....It seems this script not reading the sharename correctly?? I dont know. Please help

Error message below:
Cannot find path 'E:\scripts\NTFS\@{Path=\server01\TestShare3\}'

PS E:\scripts\NTFS> .\Set-InheritanceOptionForSpecificShares.ps1
Inheritance is enabled for  
Enabling inheritance for @{Path=\\server01\TestShare3\NOtinherited}
Get-ChildItem : Cannot find path 'E:\scripts\NTFS\@{Path=\server01\TestShare3\}' because it does not exist.
At E:\scripts\NTFS\Set-InheritanceOptionForSpecificShares.ps1:10 char:9
+        (Get-ChildItem $Input).GetAccessControl().SetAccessRuleProtection($true,$ ...
+         ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (E:\scripts\NTFS...PT\TestShare3\}:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 
Get-ChildItem : Cannot find path 'E:\scripts\NTFS\@{Path=\Server01\TestShare3\NOtinherited}' because it does not exist.
At E:\scripts\NTFS\Set-InheritanceOptionForSpecificShares.ps1:10 char:9
+        (Get-ChildItem $Input).GetAccessControl().SetAccessRuleProtection($true,$ ...
+         ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (E:\scripts\NTFS...3\NOtinherited}:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 
You cannot call a method on a null-valued expression.
At E:\scripts\NTFS\Set-InheritanceOptionForSpecificShares.ps1:10 char:8
+        (Get-ChildItem $Input).GetAccessControl().SetAccessRuleProtection($true,$ ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
creative555Author Commented:
Hi,
I tried again the script and it throws the same error. Also, i would like to do recurse on the folders that I specify. So, if I have the txt file with the following shares, I would like the script to hit all the subfolders and files underneath and if that option not check, then set that option.

Thank you so much.

I used the txt file called filename.txt and had the following info there. is this correct?

Path
\\servername\sharename
\\servername2\share02


        ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (E:\scripts\NTFS...\NOtinherited2}:String) [Get-Chi
   ldItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 
You cannot call a method on a null-valued expression.
At E:\scripts\NTFS\Set-InheritanceOptionForSpecificShares.ps1:10 char:8
+        (Get-ChildItem $Input).GetAccessControl().SetAccessRuleProtection($true,$ ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
Lionel MMSmall Business IT ConsultantCommented:
please post this file for us to see
$Input = Import-Csv 'c:\filename.csv'
looks like you have an incorrect server UNC
Path=\server01\TestShare3
should be
Path=\\server01\TestShare3

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
creative555Author Commented:
Thank you very much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.