Hello Guys, Help with this PS Script to output all folder and sub folder permission, i only have the permission from only one, how can i obtain all folders inside.

Elmi Almonte Morel 106 Reputation points
2020-08-11T02:43:58.3+00:00

strong text [CmdletBinding()]
Param (
[Parameter(Mandatory=$True,Position=0)]
[String]$AccessItem
)
$ErrorActionPreference = "SilentlyContinue"
If ($Error) {
$Error.Clear()
}
$RepPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$RepPath = $RepPath.Trim()
$FinalReport = "$RepPath\NTFSPermission_Report.csv"
$ReportFile1 = "$RepPath\NTFSPermission_Report.txt"

If (!(Test-Path $AccessItem)) {
    Write-Host
    Write-Host "`t Item $AccessItem Not Found." -ForegroundColor "Yellow"
    Write-Host
}
Else {
    If (Test-Path $FinalReport) {
        Remove-Item $FinalReport
    }
    If (Test-Path $ReportFile1) {
        Remove-Item $ReportFile1
    }
    Write-Host
    Write-Host "`t Working. Please wait ... " -ForegroundColor "Yellow"
    Write-Host
    ## -- Create The Report File
    $ObjFSO = New-Object -ComObject Scripting.FileSystemObject
    $ObjFile = $ObjFSO.CreateTextFile($ReportFile1, $True)
    $ObjFile.Write("NTFS Permission Set On -- $AccessItem `r`n")
    $ObjFile.Close()
    $ObjFile = $ObjFSO.CreateTextFile($FinalReport, $True)
    $ObjFile.Close()
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($ObjFSO) | Out-Null
    Remove-Variable ObjFile
    Remove-Variable ObjFSO
    If((Get-Item $AccessItem).PSIsContainer -EQ $True) {
        $Result = "ItemType -- Folder"
    }
    Else {
        $Result = "ItemType -- File"
    }
    $DT = Get-Date -Format F
    Add-Content $ReportFile1 -Value ("Report Created As On $DT")
    Add-Content $ReportFile1 "=================================================================="
    $Owner = (Get-Item -LiteralPath $AccessItem).GetAccessControl() | Select Owner
    $Owner = $($Owner.Owner)
    $Result = "$Result `t Owner -- $Owner"
    Add-Content $ReportFile1 "$Result `n"
    (Get-Item -LiteralPath $AccessItem).GetAccessControl() | Select * -Expand Access | Select IdentityReference, FileSystemRights, AccessControlType, IsInherited, InheritanceFlags, PropagationFlags | Export-CSV -Path "$RepPath\NTFSPermission_Report2.csv" -NoTypeInformation
    Add-Content $FinalReport -Value (Get-Content $ReportFile1)
    Add-Content $FinalReport -Value (Get-Content "$RepPath\NTFSPermission_Report2.csv")
    Remove-Item $ReportFile1
    Remove-Item "$RepPath\NTFSPermission_Report2.csv"
    Invoke-Item $FinalReport
}
If ($Error) {
    $Error.Clear()
}
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,519 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 108.7K Reputation points MVP
    2020-08-11T17:44:09.197+00:00

    Maybe something like this?

    $path = "C:\users"
    Get-ChildItem -Path $path -Recurse -Directory | Get-Acl | Format-Table
    

    Maybe this is helpful.

    Regards

    Andreas Baumgarten

    (Please don't forget to Accept as answer if the reply is helpful)

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 108.7K Reputation points MVP
    2020-08-13T17:42:22.287+00:00

    Does my answer solve your requirement?

    Regards

    Andreas Baumgarten

    (Please don't forget to Accept as answer if the reply is helpful)

    0 comments No comments

  2. 2020-08-20T01:49:31.963+00:00

    Hi, given that this post has been quiet for a while, this is a quick question and answer. Has your question been solved? If so, please mark it as an answer so that users with the same question can find and get help.
    :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.