none
Logic Error with get-acl $FolderNames | where {$_.psiscontainer -eq $true} RRS feed

  • Question

  • Hello there,

    I'm a novice to PowerShell, so please be gentle <smile>.  I've written a script to harvest ACL data from specific folders and dump the results into a csv file.   Here's my code:

    # Prompt for IIS Drive $strDrive = Read-Host "Specify InetPub Drive (e.g. C:)" # Assign IIS Drive Set-Location $strDrive # Prompt for output file location $strOutputDirectory = Read-Host "Specify output file directory (e.g. C:\Users\Bill Hamill\Desktop)" # Create & format output file $Results = $strOutputDirectory + "\Permissions.csv" $ColumnTitles = "Path,Identity,Access Level" Add-Content -Value $ColumnTitles -Path $Results $strIIS_Shares = @( "\InetPub\Scripts", "\InetPub\wwwroot\mill\de", "\InetPub\wwwroot\mill\docs", "\InetPub\wwwroot\mill\eis", "\InetPub\wwwroot\mill\letters", "\InetPub\wwwroot\mill\windows", "\InetPub\wwwroot\mill\exports", "\InetPub\wwwroot\mill\formats", "\InetPub\wwwroot\mill\oracleformats", "\InetPub\wwwroot\mill\reports", "\InetPub\wwwroot\mill\reports\import", "\InetPub\wwwroot\mill\tools\log", "\InetPub\wwwroot\mill\tools\webreports" )

    $Folders = get-acl $strIIS_Shares | where {$_.psiscontainer -eq $true} ForEach ($Folder in $Folders){$ACLs = get-acl $Folder.fullname | ForEach-Object {$_.Access} ForEach ($ACL in $ACLs){$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," + $ACL.FileSystemRights Add-Content -Value $OutInfo -Path $Results}}

    And now here's my problem:

    The script is not returning *any* results pulled from the following shares when I run this script.  The results for the rest of the shares defined above are properly dumped to the specified csv file.  

    #\InetPub\wwwroot\mill\docs
    #\InetPub\wwwroot\mill\eis
    #\InetPub\wwwroot\mill\letters
    #\InetPub\wwwroot\mill\exports
    #\InetPub\wwwroot\mill\tools\log
    #\InetPub\wwwroot\mill\tools\webreports

    All of these directories are terminal (have no sub-directories).  I believe the logic of this statement is flawed somehow:  

    $Folders = get-acl $strIIS_Shares | where {$_.psiscontainer -eq $true}

    But I can't for the life of me figure out why!  Any help out there?



    • Edited by Bill Hamill Tuesday, February 12, 2013 4:47 AM
    Tuesday, February 12, 2013 4:45 AM

Answers

  • $strIIS_Shares | Get-Item -Path {$strDrive + $_} | Foreach {
    	$n = $_.fullname
    	$_.GetAccessControl().Access | select @{n="FullName";e={$n}},@{n="Identity";e={$_.IdentityReference}},@{n="Access Level";e={$_.FileSystemRights}}
    } | Export-CSV -NoType $Results

    • Marked as answer by Bill Hamill Tuesday, February 12, 2013 3:21 PM
    Tuesday, February 12, 2013 5:13 AM
  • Simply put, you are piping your return object from Get-ACL and checking the Value called PSIsContainer for each of those objects.

    If I try this:

    $x = Get-ACL C:\
    $x|gm

    I can see that there is no Property, or Method called PSIscontainer.

    PSIsContainer is available in objects returned from Get-Item. For example:

    $y = Get-Item C:\
    $y|gm

    You can see that the object type System.IO.DirectoryInfo provides a NoteProperty called PSIsContainer.

    I think what you are attempting to do for folders is this:

    $Folders = Get-Item  $strIIS_Shares | where {$_.psiscontainer -eq $true}

    Thanks,

    Chris.


    • Edited by Dwarfsoft Tuesday, February 12, 2013 5:16 AM
    • Proposed as answer by Dwarfsoft Tuesday, February 12, 2013 5:17 AM
    • Unproposed as answer by Bill Hamill Tuesday, February 12, 2013 1:12 PM
    • Marked as answer by Bill Hamill Tuesday, February 12, 2013 3:23 PM
    Tuesday, February 12, 2013 5:16 AM

All replies

  • $strIIS_Shares | Get-Item -Path {$strDrive + $_} | Foreach {
    	$n = $_.fullname
    	$_.GetAccessControl().Access | select @{n="FullName";e={$n}},@{n="Identity";e={$_.IdentityReference}},@{n="Access Level";e={$_.FileSystemRights}}
    } | Export-CSV -NoType $Results

    • Marked as answer by Bill Hamill Tuesday, February 12, 2013 3:21 PM
    Tuesday, February 12, 2013 5:13 AM
  • Simply put, you are piping your return object from Get-ACL and checking the Value called PSIsContainer for each of those objects.

    If I try this:

    $x = Get-ACL C:\
    $x|gm

    I can see that there is no Property, or Method called PSIscontainer.

    PSIsContainer is available in objects returned from Get-Item. For example:

    $y = Get-Item C:\
    $y|gm

    You can see that the object type System.IO.DirectoryInfo provides a NoteProperty called PSIsContainer.

    I think what you are attempting to do for folders is this:

    $Folders = Get-Item  $strIIS_Shares | where {$_.psiscontainer -eq $true}

    Thanks,

    Chris.


    • Edited by Dwarfsoft Tuesday, February 12, 2013 5:16 AM
    • Proposed as answer by Dwarfsoft Tuesday, February 12, 2013 5:17 AM
    • Unproposed as answer by Bill Hamill Tuesday, February 12, 2013 1:12 PM
    • Marked as answer by Bill Hamill Tuesday, February 12, 2013 3:23 PM
    Tuesday, February 12, 2013 5:16 AM
  • Thank you so much!
    Tuesday, February 12, 2013 3:22 PM
  • Also completely successful.  Thank you so much ...
    Wednesday, February 13, 2013 4:05 AM