Formatter help

Welcome Forums General PowerShell Q&A Formatter help

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
1 year, 7 months ago.

  • Author
    Posts
  • #67075

    Participant
    Points: 1
    Rank: Member

    I am trying to produce output from relational data where two properties are of string and collection.

    Get-ChildItem 'X:\Some Path' |Get-Acl |Format-Table @{...}
    

    produces:

    Path                FileSystemRights     AccessControlType  IdentityReference  IsInherited  InheritanceFlags  PropagationFlags
    ----                ----------------     -----------------  -----------------  -----------  ----------------  ----------------
    X:\Some Path\fileA  Modify, Synchronize  Allow              dom\User000        True         None              None
                        Modify, Synchronize  Allow              dom\User001        True         None              None
                        Modify, Synchronize  Allow              dom\User002        True         None              None
                        Modify, Synchronize  Allow              dom\User003        True         None              None
    X:\Some Path\fileB  Modify, Synchronize  Allow              dom\User000        True         None              None
                        Modify, Synchronize  Allow              dom\User001        True         None              None
                        Modify, Synchronize  Allow              dom\User002        True         None              None
                        Modify, Synchronize  Allow              dom\User003        True         None              None
    

    So the content of Path is

    Convert-Path $_.PSPPath

    and the content of the remaining fields is the result of each FileSystemAccessRule in the $_.Access collection.

    Is that possible?

  • #67132

    Participant
    Points: 35
    Rank: Member

    Not with just

    Format-Table

    unfortunately, but you can do it like this:

    Get-ChildItem | Get-Acl | ForEach-Object {
        $acl = $PSItem
        $acl.Access | Add-Member -NotePropertyName Path -NotePropertyValue (Convert-Path $acl.PSPath) -PassThru
    } | Format-Table Path, FileSystemRights, AccessControlType, IdentityReference, 
                     IsInherited, InheritanceFlags, PropagationFlags
    

The topic ‘Formatter help’ is closed to new replies.