I am recursively getting a list of folders with their respective permissions in a powershell script, however when the recursive part happens my output string keeps printing the folder structure each time an example of this is:
I have a folder called C:\temp, within that folder are 2 empty folders C:\temp\folder1 and C:\temp\folder2. With my script the output would be:
I have left out the permissions for readability
C:\temp
C:\temp\folder1
C:\temp
C:\temp\folder2
I don't want this to happen I want a list of folders with their permissions and then if the permissions on a child folder are different then look at the get the child folders of that folder. This works apart from the string building which I think I need a fresh pair of eyes to look at it because I'm getting nowhere.
Appreciate the help in advance,
Sam
CODE:
Add-Type -AssemblyName System.Windows.Forms
Import-Module ActiveDirectory
$info = ""
$OutputString
$step = 0
function DisplayForm{
#Some GUI code
#$textBox takes in the base folder from the user
    if ($result -eq [System.Windows.Forms.DialogResult]::OK)
    {
        $baseFolder = $textBox.Text
        $ParentProperties = (Get-Acl $baseFolder).Access| Select-Object -ExpandProperty IdentityReference
        $OutputString = $OutputString + $baseFolder + "`r`n" + $ParentProperties + "`r`n`r`n"
        $ChildFolders = Get-ChildItem $baseFolder | where {$_.Attributes -eq 'Directory'}
        FindPriorities($baseFolder)
        $info = "SAVED TO FOLDER"
        outputList
    }
}
function FindPriorities{
    param($fileName)
    $ChildFolders = Get-ChildItem $fileName | where {$_.Attributes -eq 'Directory'}
    $step = $step + 1
    $TempString = ""
    foreach ($folder in $ChildFolders){
        $child = $fileName + "\\" + $folder.name
    $ParentProperties = (Get-Acl $fileName).Access| Select-Object -ExpandProperty IdentityReference
    $ChildProperties = (Get-Acl $child).Access| Select-Object -ExpandProperty IdentityReference
    $parentString=""
    foreach ($p in $ParentProperties){
        $parentString= $parentString + $p
    }
    $childString=""
    foreach ($c in $childProperties){
        $childString = $childString + $c
    }
    if($childString -ne $parentString){
        $OutputString = $OutputString + $child + "`r`n" + $ChildProperties + "`r`n`r`n"
        FindPriorities ($child)
    }else{
        $OutputString = $OutputString + $child + "`r`n" + $ChildProperties + "`r`n`r`n"
    }
}
}
function outputList{
    $OutputString
}
DisplayForm
 
    