Some articles are posted as Images, Please use Computers to go through them for best experience. For phone users, switch to Web Version

Windows Script - Fetching Ownership details, Inheritance status and NTFS Permissions of Root and all it's Subfolders

 <# Created By Abhishek Bansal

Read Note 

Script Usage - Useful in fetching Owners details, Inheritance status, NTFS Permissons of Parent / Root folder & all the sub folders.

Pre requisites :: Copy all the code into a text file, save it with an extension ".PS1".Once saved, run this script as Administrato / from ID that has access to the folders.

Execution & Outputs :: Once executed, there will be multiple Outifle files created which would be -

FolderInheritance.csv - Containing Root folder and subfolders Ownnership details along with inheritance status.

FolderACL.csv - Containing Root folder and subfolders NTFS permissions.

Along with above, Errorlogs.csv can also be produced if there are any errors encountered while executing this script.#>

 


$RootPath = Read-Host "Enter Full Absolute Path of the Root folder = " 

$subfolders = Get-ChildItem -Path "$RootPath" -Filter * -Recurse -Directory | Select * #Listing all the Subfolders inside Root Path.


Get-Acl -Path $RootPath  |  Select-Object -Property @{n="Path";e={$RootPath}},Owner,@{n="Inheritance Blocked";e={$_.AreAccessRulesProtected}} | Export-Csv ./FolderInheritance.csv -NoTypeInformation -Append

(Get-Acl -Path $RootPath).Access | Select @{n="Path";e={$RootPath}},IdentityReference,FileSystemRights,AccessControlType | Export-Csv ./FolderACL.csv -NoTypeInformation -Append


foreach($Subfolder in $subfolders)

    {

    $Subfolderpath = $Subfolder.FullName

    try{

    Get-Acl -Path $Subfolderpath  |  Select-Object -Property @{n="Path";e={$Subfolderpath}},Owner,@{n="Inheritance Blocked";e={$_.AreAccessRulesProtected}} | Export-Csv ./FolderInheritance.csv -NoTypeInformation -Append

    (Get-Acl -Path $Subfolderpath).Access | Select @{n="Path";e={$Subfolderpath}},IdentityReference,FileSystemRights,AccessControlType | Export-Csv ./FolderACL.csv -NoTypeInformation -Append


       }


    catch{

    $Subfolderpath | Select @{n="Path";e={$Subfolderpath}},@{n="Errorinfo";e={"Path Not accessible."}} | Export-Csv ./Errorlogs.csv -NoTypeInformation -Append

    }


 }

No comments:

Post a Comment