none
Get-ACL error message. RRS feed

  • Question

  • Hi all,

       I have been writing minor PS scripts for a couple of weeks now and have slowly increasing my knowledge. I have written the following script and what it is supposed to do is as follows:

    List's the child items of the folder that is input in a command. It then outputs it in a Gridview to allow for the specific subfolder to be chosen, and at that point, I am looking to have it list the permissions of that selected folder in a CSV file.

    My issue is that after selecting the folder in the Gridview pane, I am getting the following error: 

    Get-Acl : Cannot find path 'Projects' because it does not exist.
    At I:\Administration\Scripts\Get Folder PermissionsV1.ps1:9 char:32
    +                                            Get-Acl | Format-List | export-csv c:\Permissions ...
    +                                            ~~~~~~~
        + CategoryInfo          : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
        + FullyQualifiedErrorId : GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand

    The code is listed here as well. I've looked up this error, but not quite sure of the direction to head.

    $server = read-host "Enter the name of the server you want information about."
    $folder = read-host "Enter the folder you want information about."
    Write-Host "Please be patient as the file will take some time to populate."
    Get-ChildItem "\\$server\$folder" -Filter * | 
                       where {$_.PsIsContainer} |
                          Select -ExpandProperty Name | 
                                    Sort |
                                        Out-GridView -PassThru |
            				                   Get-Acl | Format-List | export-csv c:\Permissions.csv -NoTypeInformation
    Invoke-item c:\Permissions.csv

    Wednesday, August 27, 2014 1:33 PM

Answers

  • Try it this way:

    Get-ChildItem \\$server\$folder -Directory |
         Out-GridView -PassThru |
         get-acl |
         export-csv access.csv -NoType


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, August 27, 2014 1:43 PM
    • Marked as answer by Perry's I.T. Guy Wednesday, August 27, 2014 2:11 PM
    Wednesday, August 27, 2014 1:43 PM

All replies

  • Remove Format-List.  You cannot export this.  You can only export objects.


    ¯\_(ツ)_/¯

    Wednesday, August 27, 2014 1:38 PM
  • Try it this way:

    Get-ChildItem \\$server\$folder -Directory |
         Out-GridView -PassThru |
         get-acl |
         export-csv access.csv -NoType


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, August 27, 2014 1:43 PM
    • Marked as answer by Perry's I.T. Guy Wednesday, August 27, 2014 2:11 PM
    Wednesday, August 27, 2014 1:43 PM
  • Here:

    Select -ExpandProperty Name | 

    You're only getting the Name of the folder (no path information), so Get-ACL is looking for that folder in the current directory.  You need to pass Get-ACL the fullname so that it has the rest of the path information.

    Here's a function you can use if you want to just list the Name in the gridview, but still pass the entire object on the Get-ACL so that it can have access to the fullname:

    http://gallery.technet.microsoft.com/scriptcenter/Select-FromGridView-521a56d8


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Wednesday, August 27, 2014 1:44 PM
    Moderator
  • It is only necessary to pass the object to Get-Acl.  Remember that PowerShell is an object system.

    Get-ChildItem \\$server\$folder -Directory |
        
    Out-GridView -PassThru |
        
    get-acl

    This works as expected.

    You cannot export the output of Format-List in any meaningful way.  You can output it as text.


    ¯\_(ツ)_/¯

    Wednesday, August 27, 2014 1:47 PM
  • This saves the output of format-list

    Get-ChildItem \\$server\$folder -Directory |
         Out-GridView -PassThru |
         get-acl |
         format-list |
         Out-File out.txt


    ¯\_(ツ)_/¯

    Wednesday, August 27, 2014 1:48 PM
  • It is only necessary to pass the object to Get-Acl.  Remember that PowerShell is an object system.

    Get-ChildItem \\$server\$folder -Directory |
        
    Out-GridView -PassThru |
        
    get-acl

    This works as expected.

    You cannot export the output of Format-List in any meaningful way.  You can output it as text.


    ¯\_(ツ)_/¯

    Yes, but the Format-List is not what's causing the error. 

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Wednesday, August 27, 2014 1:51 PM
    Moderator
  • Both are causing failures;  Here is what I posted above:

    Get-ChildItem \\$server\$folder -Directory |
         Out-GridView -PassThru |
         get-acl |
         export-csv access.csv -NoType

    It solves both problems.


    ¯\_(ツ)_/¯

    Wednesday, August 27, 2014 1:54 PM
  • If you had posted that originally, I wouldn't have added the post about select-object problem.

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Wednesday, August 27, 2014 1:57 PM
    Moderator
  • Hi jrv and mjolinor,

        JRV's solution worked. I'm just working through it so I can understand the process a little better. I think I'd been on the right path, but needed that extra kick in the arse. 

    Thanks for the info from both of you though. Much appreciated. Hopefully I'll get to the point where I can answer questions instead of asking them. 

    Wednesday, August 27, 2014 2:11 PM
  • If you had posted that originally, I wouldn't have added the post about select-object problem.

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    I posted it immediately after my first post and before I was able to see your post.  Slow servers.  I wanted to test the exact code for typos so I just noted that the format-list would not be usable. 

    Yes- the error is only because the OP is using solely the Name as you pointed out.


    ¯\_(ツ)_/¯

    Wednesday, August 27, 2014 2:11 PM