0

I am trying to get all the permissions on a directory using the first function, and the folders with broken inheritance using the second function. Then I want to output the both of them using the third function, but I am getting just the first result the "permission" without the second one!

function Get-Permissions3($folder) {
    $Paths = Get-ChildItem $folder -Recurse 
    foreach ($p in $Paths) {
        $Permissions = (Get-Acl $p.FullName).Access
        $Permissiontable = $Permissions |
                           Select-Object @{name="FullName";expression={$p.FullName}},
                               @{name="IdentityReference";expression={$_.IdentityReference}},
                               @{name="FileSystemRights";expression={$_.FileSystemRights}},
                               @{name="IsInherited";expression={$_.IsInherited}}
        $Permissiontable
    }
} 

function Get-BrokenInheritance($Directory) {
    $D = Get-ChildItem $Directory -Directory -Recurse |
         Get-Acl |
         where {$_.Access.IsInherited -eq $false}
    $BrokenInheritance = $D | Select-Object @{name="Without Inheritance";expression={$_.Path}}
    $BrokenInheritance
}

function Get-FolderAnalysis($Path) {
    Write-Output "Output Permissions"
    Get-Permissions3($Path)

    Write-Output "Output Broken Inheritance"
    Get-BrokenInheritance($Path)
}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Morenkashi
  • 33
  • 6

1 Answers1

1

In your 3rd function i.e. Get-FolderAnalysis, you are not actually combining the results of the first two functions. You are rather invoking them on separate lines and that's it. Hence, you don't see both your outputs. You can overcome that by using Calculated properties like done below -

Function Get-FolderAnalysis($Path)
{  
    Write-Output "Output Permissions"
    $Permissions = Get-Permissions3($Path)

    Write-Output "Output Broken Inheritance"
    $BrokenInheritance = Get-BrokenInheritance($Path)

    $Permissions | Select-Object *, @{ name="Output Broken Inheritance"; expression={Get-BrokenInheritance($Path)}}
}
Vivek Kumar Singh
  • 3,223
  • 1
  • 14
  • 27
  • But i just want the name of the Folders which have disabled Inheritance – Morenkashi Jul 20 '18 at 11:51
  • @Morenkashi if You just want name of the folder with broken inheritance - do this ls -path c:\temp -Recurse| Get-Acl |%{$_|where {$_.access.isinherited -eq $false}} This does work for me – Tomek Jul 20 '18 at 13:13
  • yes its work but i want to export it to CSV file – Morenkashi Jul 23 '18 at 11:40