Struggling with migration of Grid to Table in v3

Hi guys, I know this question has been asked several times but the examples and source code aren’t providing any clarity on a migration path to v3. The biggest frustration seems to be around how to move from server-side processing where we run powershell cmdlets and pump the output to Out-UDGridData. If anyone could provide an example of migrating the following code (I’ve built this from scratch to include the components I’m reading other people struggling with) I think it would help several people on this forum out and I’d personally be very appreciative.

In essence, the code runs a Get-WhateverCommand that returns a list of users connected to a system. That list of users is printed to table along with a button that calls a function to log the user off when required.

V2 code needing conversion to v3:

$MyPage = New-UDPage -Name "User disconnection system" -Icon building -Content {
    New-UdGrid -Title "Users logged on" -Headers @("User", "Disconnect User") -Properties @("UserName", "DisconnectSession") -AutoRefresh -RefreshInterval 900 -Endpoint {
    #The below powershell modules are available to the whole system
    Import-Module MyModule1
    Import-Module MyModule2
    $UserList = Get-Content -Raw c:\inetpub\poshud\usersessions.json | ConvertFrom-Json
    $(Foreach ($User in $UserList) {
        Get-UserSession -ComputerName $User.ComputerName -ErrorAction SilentlyContinue | ForEach-Object {
              [PSCustomObject]@{
                   Server = $_.server.ServerName
                   UserName = $_.UserName
                   SessionID = $_.SessionID
                   DisconnectSession = New-UDButton -Text "Disconnect" -OnClick {New-UDEndpoint -Endpoint { 
                                Import-Module MyModule1
                                Disconnect-User -Param1 $ArgumentList[0] -Param2 $ArgumentList[1] -Force -ErrorAction SilentlyContinue | out-null
                                Show-UDToast -Message "Disconnected successfully, please refresh your screen" -Duration 4000 -Icon check
                            } -ArgumentList $_.SessionID, $_.server.ServerName
              }
          } 
    })| Out-UDGridData
} -ServerSideProcessing
}

@adam are you able to help with this one at all? Guidance on any of the components (using buttons, inserting output from a ps command) would be greatly appreciated.

Hey @mmcdougall,

I wrote a blog post on server-side processing today: https://blog.ironmansoftware.com/universal-dashboard-server-side-table/

For the buttons, you will want to consider using New-UDTableColumn instead of just putting the button in the data for the column: https://docs.ironmansoftware.com/dashboard/components/data-display/table#table-with-custom-column-rendering

I didn’t test this but it will be something like this

    New-UdGrid -Title "Users logged on"  -LoadData {
    #The below powershell modules are available to the whole system
    Import-Module MyModule1
    Import-Module MyModule2
    $UserList = Get-Content -Raw c:\inetpub\poshud\usersessions.json | ConvertFrom-Json
    $(Foreach ($User in $UserList) {
        Get-UserSession -ComputerName $User.ComputerName -ErrorAction SilentlyContinue | ForEach-Object {
              @{
                   Server = $_.server.ServerName
                   UserName = $_.UserName
                   SessionID = $_.SessionID
                   DisconnectSession = $_
              } 
    })| Out-UDGridData
} -Columns @(
   New-UdTableColumn -Name 'Server'
   New-UdTableColumn -Name 'UserName'
   New-UdTableColumn -Name 'SessionId'
   New-UdTableColumn -Name 'DisconnectSession' -Render { 
           $Item = $Body | ConvertFrom-Json 
                                Import-Module MyModule1
                                Disconnect-User -Param1 $Item.SessionID -Param2 $Item.ServerName -Force -ErrorAction SilentlyContinue | out-null
                                Show-UDToast -Message "Disconnected successfully, please refresh your screen" -Duration 4000 -Icon check
   }
)
2 Likes

Thank you so much @adam, I’ll give that a go. @TiX may benefit from your response here also.

1 Like