none
ACL and Ownership RRS feed

  • Question


  • what modification i need to introduce to the following script in order to get ownership information too:

    Get-ChildItem "C:\DFSRoots\DFS\Folder_Redirection" -Recurse | ?{ $_.PsIsContainer } | %{
    $Path = $_.FullName
    # Include inherited rights from the report
    (Get-Acl $Path).Access | Select-Object `
        @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
        InheritanceFlags, PropagationFlags, FileSystemRights
    } | Export-CSV "C:\exported\Permissions4.csv"

    Thanks.

    Junior

    Wednesday, November 20, 2019 10:12 PM

Answers

  • Ok - here is the correct approach to this using modern PowerShell methods.  This will give you some idea of what PS is and how it is intended to work.

    $properties = @(
        @{n='Path' ;e={$file.Fullname}},
        @{n='Owner';e={$acl.Owner}},
        'IdentityReference',
        'AccessControlType',
        'InheritanceFlags',
        'PropagationFlags',
        'FileSystemRights'
    )
    Get-ChildItem C:\DFSRoots\DFS\Folder_Redirection -Recurse -Directory -PipelineVariable file |
        Get-Acl -PipelineVariable acl| 
        Select-Object -ExpandProperty Access|
        Select-Object $properties |
        Export-CSV C:\exported\Permissions4.csv

    Before you go any further or ask another question please take the time to learn PowerShell.


    \_(ツ)_/

    • Marked as answer by Junior Gómez Thursday, November 21, 2019 2:10 PM
    Thursday, November 21, 2019 5:00 AM
    Moderator

All replies

  • Check the Owner property.

    Get-Acl $path | select Owner

    You could have figured this out by yourself by typing:

    Get-Acl $path | Get-Member


    \_(ツ)_/

    Wednesday, November 20, 2019 10:16 PM
    Moderator
  •  

    this is the result of the current script:

    Path IdentityReference   |AccessControlType |InheritanceFlags |PropagationFlags FileSystemRights


    F:\Shares\filesIPO\2016_CIF_Bond ADOPS\File Server Admins Allow ContainerInherit, ObjectInherit  None FullControl

    Thanks jrv, but what im trying to accomplish is to get the owner  as a part of this information, one more colum with the owner information.

    Wednesday, November 20, 2019 10:30 PM
  • I posted that answer:

    Get-Acl $path | select Owner

    OR

    $acl = Get-Acl $path
    $acl.Owner


    \_(ツ)_/


    • Edited by jrvModerator Wednesday, November 20, 2019 10:32 PM
    Wednesday, November 20, 2019 10:31 PM
    Moderator
  • if do Get-Acl $path | select Owner

    i just get owner information and not the rest of info like Get-Acl $path | select Access

    im trying to get a way to get owner + accessrights

    regards.

    Wednesday, November 20, 2019 10:35 PM
  • You have to add that to your script. Did you write the script?


    \_(ツ)_/

    Wednesday, November 20, 2019 11:43 PM
    Moderator
  • i know i have to add it, but where? how?, thats why im here, i wrote part of it, im still learning sorry.

    thanks.

    junior


    Thursday, November 21, 2019 2:15 AM
  • Start by formatting code correctly and posting it correctly. That exercise will help you understand the code you think you wrote but just copied and are trying to change.

    Never run code you do not understand.

    Here is a place to start that can help you understand how to structure code so it is understandable and readable.

    First read this: How to post code in Technet Forums

    Next fix your original post so it is readable.

    Then read this:  The PowerShell Best Practices and Style Guide


    \_(ツ)_/

    Thursday, November 21, 2019 4:49 AM
    Moderator
  • Ok - here is the correct approach to this using modern PowerShell methods.  This will give you some idea of what PS is and how it is intended to work.

    $properties = @(
        @{n='Path' ;e={$file.Fullname}},
        @{n='Owner';e={$acl.Owner}},
        'IdentityReference',
        'AccessControlType',
        'InheritanceFlags',
        'PropagationFlags',
        'FileSystemRights'
    )
    Get-ChildItem C:\DFSRoots\DFS\Folder_Redirection -Recurse -Directory -PipelineVariable file |
        Get-Acl -PipelineVariable acl| 
        Select-Object -ExpandProperty Access|
        Select-Object $properties |
        Export-CSV C:\exported\Permissions4.csv

    Before you go any further or ask another question please take the time to learn PowerShell.


    \_(ツ)_/

    • Marked as answer by Junior Gómez Thursday, November 21, 2019 2:10 PM
    Thursday, November 21, 2019 5:00 AM
    Moderator
  • Thank you jrv, looking forward to be as good on powershell as your are, hard but not imposible.

    Junior.

    Thursday, November 21, 2019 2:11 PM
  • Thank you jrv, looking forward to be as good on powershell as your are, hard but not imposible.

    Junior.

    Not really that hard but it does take some formal approach. I recommend a good book then you will be able to leverage blogs and videos for added detail.


    \_(ツ)_/

    Thursday, November 21, 2019 3:22 PM
    Moderator