question

Elmi06 avatar image
0 Votes"
Elmi06 asked YoungYang-MSFT answered

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.

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
1 Vote"
AndreasBaumgarten answered AndreasBaumgarten edited

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)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered

Does my answer solve your requirement?

Regards

Andreas Baumgarten

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered

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.
:)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.