Displaying Get-ACL from user input

I want to build a dashboard that can that can take two inputs for a $Server and $Folder then when you submit it, it does a Get-ACL -path \$server$folder and displays the returned data. This is what I have so far but the returned data in not really readable. I don’t know if there’s another way to do this.

Here is what i have. If i take away the out-string I get a different error.

indent preformatted text by 4 spaces



            New-UDHtml -Markup "<h5>Security Permission Checker</h5>" 
        New-UDHtml -Markup "<h6>Please Enter Server and Share Path</h6>"
        New-UDRow {
           New-UDColumn -Id 'LeftColumn4' -LargeSize 6 -Content {
                New-UDCard -Endpoint {
                    New-UDInput -Title 'Content is displayed when Permission Check completes.'  -Endpoint {
                    
                    param(
                    [String]$server,
                    [String]$folder
                    )

                Add-UDElement -ParentId 'RightColumn4' -Content {               
                
                New-UDElement -Tag 'div' -Endpoint {
                $secperm = ( Get-Acl -Path \\$server\$folder| Format-Table -Wrap | Out-String ) -join '<br/>'

                New-UDCard -Title 'Results'-Content {
                New-UDHtml -Markup $secperm 
                }#new card
                }#new udelement
                           
                New-UDHtml -Markup '<button class="btn ud-button" type="button" onClick="window.location.reload();">Reset Page</button>'
                }#element
                   
                }#endpoint
                
                }#udcard
                
                }#column
                
           New-UDColumn -Id 'RightColumn4' -LargeSize 6 -Content {
           }#column
        }#top column

Think you would be better outputting $secperm to a grid or a table it should then work fine…I am using a function to return folder sizes, and I output to a grid and it’s all good. I am sure this will fix your issue. Look on www.poshud.com for some examples of how to output your data to either a table or a grid.

1 Like

You are doing some very bad things there using FT etc
Try this revised section .
This will throw a display error.
what it means is UD cannot handle the nested access permissions for the owner.
So once you can manipulate the results from the get-acl into a normal row/column arrangement , it wil display fine

               New-UDElement -Tag 'div' -Endpoint {
                $Session:secperm = Get-Acl -Path \\$server\$folder
                  New-UDTable  -Title "Results" -Header  @("Path","Owner","Access")  -Endpoint {
                    $Session:secperm | Out-UDTableData -Property @("Path","Owner","Access") 
                }

              
               
               }#new udelement

This is more what I mean

        New-UDPage -Name "GetACL"  -Content {


       New-UDHtml -Markup "<h5>Security Permission Checker</h5>" 
       New-UDHtml -Markup "<h6>Please Enter Server and Share Path</h6>"
       New-UDRow {

               New-UDCard -Endpoint {
                   New-UDInput -Title 'Content is displayed when Permission Check completes.'  -Endpoint {
                   
                   param(
                   [String]$server,
                   [String]$folder
                   )

               Add-UDElement -ParentId 'RightColumn4' -Content {               
               
               New-UDElement -Tag 'div' -Endpoint {
                $Acl= Get-Acl -Path \\$server\$folder
                $Session:secperm  =    ForEach ($Access in $Acl.Access) {
                
                    $object = [PSCustomObject]@{FolderName=$Folder;GroupOrUser=$Access.IdentityReference;Permissions=$Access.FileSystemRights;Inherited=$Access.IsInherited}
                    $object
                           }
                                     
               

                New-UDTable  -Title "Results" -Header  @('Folder Name','Group or User','Permissions','Inherited')  -Endpoint {
                    $Session:secperm | Out-UDTableData -Property @('FolderName','GroupOrUser','Permissions','Inherited')  
                }

              
               
               }#new udelement
                          
               New-UDHtml -Markup '<button class="btn ud-button" type="button" onClick="window.location.reload();">Reset Page</button>'
               }#element
                  
               }#endpoint
               
               }#udcard
               
               }#column
               
          New-UDColumn -Id 'RightColumn4' -LargeSize 6 -Content {
          }#column


    }
1 Like

Thanks so much for the help. I am really just learning how to program in powershell. What bad things am I doing? I want to know so I dont do it in the future :slight_smile:

thank you…

Hi,

the code

$secperm = ( Get-Acl -Path \\$server\$folder| Format-Table -Wrap | Out-String ) -join '<br/>'

The main “bad thing” you are doing is using Format-table. This is really only ever useful if you are outputting your result to a powershell console. The resultant object you get $secperm is just a string which then means you are having to manipulate text (which is why you are doing the join). UD understands powershell objects (some exclusions apply :slight_smile: )

Have a look at the commands

 Get- ACL -path c:\temp 
 Get- ACL -path c:\temp | get-member
 Get- ACL -path c:\temp | select-object path,IdentityReference
 Get- ACL -path c:\temp | select-object * |Out-gridview

First one just outputs limited data to the screen , it will be selective what it will show you
second one tells potentially what you what you can select from the object
Third one just selects some properties from the object
Fourth selects all possible things and pipes it to out-gridview

Using out-gridview helps you see what you are actually going to give to something that is relying on the result.
So in the case where you are wanting the information to be used later by a table, then out-gridview (ogv for short) is a good tool to see if you have selected things properly

1 Like

I almost got it now. There just a weird formatting thing i cant figure out. The accesstostring that shows all the groups is not formatted at all. It is just one long line basically.

indent preformatted text by 4 spaces
    New-UDHtml -Markup "<h5>Security Permission Check</h5>" 
New-UDInput -Title “Please Enter Server and Folder Name” -Endpoint {
        param(
        [Parameter(Mandatory=$true)]
        [string]$server,
        [string]$folder 
        )  

New-UDInputAction  -Content { 

    New-UDElement -Tag 'div'  -Content {

    New-UDTable -Title 'Results'  -Headers  @('Path', 'Owner' , 'Access') -Endpoint {
            Invoke-Command -ScriptBlock { Get-Acl -Path \\$server\$folder| Select-Object `
            @{name = 'Path'; expression = {Convert-Path $_.Path }},
            @{name = 'Owner'; expression = { $_.Owner }},
            @{name = 'Access'; expression = { $_.AccessToString } }   | Out-UDTableData -Property @('Path' , 'Owner', 'Access')
            }
            }
            
            New-UDHtml -Markup '<button class="btn ud-button" type="button" onClick="window.location.reload();">Reset Page</button>'

    }#close ud-element 

    }#close input action

    }#close input

@psDevUK. Any idea how to get the accesstostring to show up on multiple lines and not like one long line. I just cant figure it out. I tried putting a foreach loop in the accesstostring but that doesn’t work either.

New-UDInput -Title “Please Enter Server and Folder Name” -Endpoint {
        param(
        [Parameter(Mandatory=$true)]
        [string]$server,
        [string]$folder 
        )  

New-UDInputAction  -Content { 

    New-UDElement -Tag 'div'  -Content {

        New-UDTable -Title 'Results'  -Headers  @('Path', 'Owner' , 'Access') -Endpoint {
        Get-Acl -Path \\$server\$folder| Select-Object `
        @{name = 'Path'; expression = {Convert-Path $_.Path }},
        @{name = 'Owner'; expression = { $_.Owner }},
        @{name = 'Access'; expression = { $_.AccessToString } }   | Out-UDTableData -Property @('Path' , 'Owner', 'Access')
        }
        
            
            New-UDHtml -Markup '<button class="btn ud-button" type="button" onClick="window.location.reload();">Reset Page</button>'

   }

    }
    
    }

}

Hey @gerard off work today so trying not to be a keyboard warrior, but I cannot help not being on my computer…anyways just want to say thanks to @BritV8 for your input, some good advice shared there…so without trying your whole script, I had a similar problem, I got asked by a manager to record people visiting the SALES dashboard I created, I had the exact same problem, that the multiple text line file I was storing the visitors in would always display as one huge line, which made it very difficult to read. So to get each line of the text file output into it’s own line I did this:-

New-UDColumn -Size 12 -Endpoint  {
    New-UDHeading -Text "Welcome $user"
    "$User logged in at $(get-date)" | Out-File "$Root\Visitors.txt" -Append

}

New-UDRow -Columns {
New-UDColumn -size 12 -Endpoint {
$info = get-content “$Root\Visitors.txt”
$result = Foreach ($line in $info){
New-UDHtml -Markup (“< b>$line< /b > < br >”)
New-UDHtml -Markup (“< br >”)
}
New-UDLink -Text “Visitors” -OnClick {
Show-UDModal -Content {
New-UDHeading -Text “Visitors To This Dashboard” -Size 4
$result
}
}
} -AutoRefresh -RefreshInterval 5
}

I hope this provides some assistance I know other members like @BoSen29 has provided a multi-line answer here:- New Lines in New-UDButton (`n)
I ended up using the example @leeberg posted here:- How do I display output in Format-List style? - #7 by MadWithPowerShell

to get my solution working…let me know if you need more assistance, but hopefully this will give you an answer. Peace

P.S only just seen the BR tags were not displaying so had to add an extra space to get them to show but use that without the spaces

1 Like

I think you can do HTML

inside the grid in order to separate the string into lines.
Havent actually tried it yet, will give this a go after work.

1 Like

I must be dense. I just cant get it to work.

Dude don’t ever feel like that. I just spent an hour trying to figure out why invoke-item didn’t work in a grid button in IIS but worked fine running dashboard locally? So I used a modal and new-Udlink to achieve same result. But feel it took me way to long to think about that. Anyways I am back in the office tomorrow so will try your script. And if I can fix it will post my results back. Peace

1 Like

Hi @gerard
Is this what you are looking for? I looped in every access and add Path as a property in output. This will work in Tables as well as in Grid.

If (-Not (Get-Module UniversalDashboard.Community -ErrorAction SilentlyContinue)) {
Import-Module UniversalDashboard.Community
}

$HomePage = New-UDPage -Name “HomePage” -Title “HomePage” -Icon home -Content {
New-UDInput -Title “Please Enter Server and Folder Name” -Endpoint {
param(
[Parameter(Mandatory=$true)]
[string]$server,
[string]$folder
)

                New-UDInputAction  -Content { 

                    New-UDElement -Tag 'div'  -Content {
                        New-UDTable -Title 'Results'  -Headers  @('Path', 'Owner' , 'Access') -Endpoint {
                            $Permissions = (Get-Acl -Path \\$server\$folder).Access | 
                            ForEach-Object { 
                                $_ | Add-Member -MemberType NoteProperty -Name Path -Value \\$server\$folder -PassThru }
                                    $Permissions | Select-Object `
                                        @{name = 'Path'; expression = {Convert-Path $_.Path.ToString() }},
                                        @{name = 'Owner'; expression = { $_.IdentityReference.ToString() }},
                                        @{name = 'Access'; expression = { $_.FileSystemRights.ToString() } } | Out-UDTableData -Property @('Path' , 'Owner', 'Access')
                        }

                        
                    New-UDHtml -Markup '<button class="btn ud-button" type="button" onClick="window.location.reload();">Reset Page</button>'
                }
            }
        }

}

$Theme = Get-UDTheme Darkdefault
$Dashboard = New-UDDashboard -Title “Status” -Pages @($HomePage) -Theme $Theme
Start-UDDashboard -Name “Status” -Port 10002 -Dashboard $Dashboard -AutoReload

If you want to ignore any Owner put it in where-object

                                    $Permissions | where-object {$_.IdentityReference -ne "CREATOR OWNER"} | Select-Object `
                                        @{name = 'Path'; expression = {Convert-Path $_.Path.ToString() }},
                                        @{name = 'Owner'; expression = { $_.IdentityReference.ToString() }},
                                        @{name = 'Access'; expression = { $_.FileSystemRights.ToString() } }
2 Likes

thanks so much. that is basically it. the only other thing i was trying to do was only have the path show once but ill take this.

I was trying a loop on just the identity reference and file system rights and that just wasnt working.
i have to look up how this loop works but thank you again.

Permissions = (Get-Acl -Path \\$server\$folder).Access | ForEach-Object { _ | Add-Member -MemberType NoteProperty -Name Path -Value \$server$folder -PassThru }

Easy way to get a workaround is display Path name in Table Title and keep Owner and permission properties in table.

Great work @Abhijit , was just about to look at this now, but seen you chipped in a working solution whilst I was fast asleep…So @gerard someone else beat me too it, but great to see this community is thriving with help. Was going to mention a way to fix your PATH only showing once, but again @Abhijit has provided a working solution. I hope you learnt from this post and thanks for asking, as it sucks not knowing how to do something if all you need is a bit of guidence or a helpful solution which hopefully you will learn from and incorporate certain aspects of this into furture dashboards with the know-how you gained.

2 Likes