Missing data in Out-UDGridData

Hey

Disclaimer: UniversalDashboard is new to me as of yesterday :smiley:

Put together a dashboard that queries AD for locked out accounts then queries our DC’s for the related logs and outputs the relevant information.

The dashboard runs fine, albeit rather slowly. The issue I’m having is that when it generates the dashboard it only shows 1 locked out user even though i know there are more than 1.

C:\Users\> Search-ADAccount -LockedOut

AccountExpirationDate :
DistinguishedName     : CN=User1,OU=OU3,OU=OU2,OU=OU1,DC=company,DC=company,DC=com
Enabled               : True
LastLogonDate         : 21/09/2019 06:59:53
LockedOut             : True
Name                  : User1
ObjectClass           : user
ObjectGUID            : 5a44dc03-4220-4da4-8670-64b43fe3e24e
PasswordExpired       : False
PasswordNeverExpires  : False
SamAccountName        : User1ID
SID                   : S-1-5-21-2432804934-1552621410-843620848-20998
UserPrincipalName     : User1@company.company.com

AccountExpirationDate :
DistinguishedName     : CN=User2,OU=OU3,OU=OU2,OU=OU1,DC=company,DC=company,DC=com
Enabled               : True
LastLogonDate         : 22/09/2019 07:53:34
LockedOut             : True
Name                  : User2
ObjectClass           : user
ObjectGUID            : 36fc3a83-f284-4d36-b0b5-18527ce4bba1
PasswordExpired       : False
PasswordNeverExpires  : False
SamAccountName        : User2ID
SID                   : S-1-5-21-2432804934-1552621410-843620848-24974
UserPrincipalName     : User2@company.company.com

AccountExpirationDate :
DistinguishedName     : CN=User3,OU=OU3,OU=OU2,OU=OU1,DC=company,DC=company,DC=com
Enabled               : True
LastLogonDate         : 21/09/2019 21:57:23
LockedOut             : True
Name                  : User3
ObjectClass           : user
ObjectGUID            : a2356195-33e5-4bb4-a3eb-24d1f93b4da7
PasswordExpired       : False
PasswordNeverExpires  : False
SamAccountName        : User3ID
SID                   : S-1-5-21-2432804934-1552621410-843620848-56100
UserPrincipalName     : User3@company.company.com

Search-AdAccount -LockedOut | %{Get-LockedOutLocation $_.SamAccountName} | Out-UDGridData                                                                                                             {
  "draw": null,
  "recordsTotal": 3,
  "data": [
    {
      "User": "User1ID",
      "DomainController": "DC.company.company.com",
      "EventId": 4740,
      "LockedOutTimeStamp": {
        "value": "2019-09-27T12:48:21.3472584+01:00",
        "DateTime": "27 September 2019 12:48:21"
      },
      "Message": "A user account was locked out.",
      "LockedOutLocation": "ServerA"
    },
    {
      "User": "User2ID",
      "DomainController": "DC.company.company.com",
      "EventId": 4740,
      "LockedOutTimeStamp": {
        "value": "2019-09-27T13:12:22.3800166+01:00",
        "DateTime": "27 September 2019 13:12:22"
      },
      "Message": "A user account was locked out.",
      "LockedOutLocation": "Computer1"
    },
    {
      "User": "User3ID",
      "DomainController": "DC.company.company.com",
      "EventId": 4740,
      "LockedOutTimeStamp": {
        "value": "2019-09-27T13:13:41.6171196+01:00",
        "DateTime": "27 September 2019 13:13:41"
      },
      "Message": "A user account was locked out.",
      "LockedOutLocation": "Laptop1"
    }
  ],
  "recordsFiltered": 3

This shows the expected outcome of the dashboard

This is the dashboard code
Import-Module UniversalDashboard.Community

. "E:\Scripts\UniversalDashboard\Get-LockedoutLocation.ps1"

Get-UDDashboard | Stop-UDDashboard
$endpointinit = New-UDEndpointInitialization -function "Get-LockedoutLocation"
$dashboard = New-UDDashboard -Title "Active Directory Locked-out Users" -EndpointInitialization $endpointinit -Content {
    New-UDGrid -title 'Current Locked-out Users' -Headers @("User", "Locked Out Time", "Domain Controller", "Lockout Source") -Properties @("User", "LockedOutTimeStamp", "DomainController", "LockedOutLocation") -PageSize 12 -endpoint {
        Search-AdAccount -LockedOut | %{Get-LockedOutLocation $_.SamAccountName} | Out-UDGridData
    }

}

Start-UDDashboard -Dashboard $dashboard -Port 8080 -AutoReload

Link to Get-LockedoutLocation script

What the dashboard actually returns

Am i missing something obvious ?

lastly, as i mentioned at the beginning performance of this is very poor (takes like 2 minutes to return 3 locked users) but if i break the code out and run segments on their own it returns almost instantly. Does anyone have any recommendations on ways to improve the performance?

Welcome to world of UD!

I think whats happening here, is that it outputs the last object - or actually all object, just one by one and therefore only the last is visible.
You need to put those locked out users in an collection and then | out-griddata them.

Instead of:

Search-AdAccount -LockedOut | %{Get-LockedOutLocation $_.SamAccountName} | Out-UDGridData

I’m not near a computer I can test on at the moment, but try to run this manually:

$Test = Search-AdAccount -LockedOut | %{Get-LockedOutLocation $_.SamAccountName} | FT
$Test

If it looks alright, try to add this to your grid instead:

$Test = Search-AdAccount -LockedOut | %{Get-LockedOutLocation $_.SamAccountName} | FT
$Test | out-griddata

Or maybe not, I thought this would yield the same result as you:

New-UDGrid -Title "test grid" -Headers @("SamAccountName","Name") -Properties @("SamAccountName","Name") -Endpoint{
            Get-ADGroupMember 922 | Foreach {Get-ADUSer $_.SAMAccountname} | Out-UDGridData
        }