Trying to create a grid of AD user accounts but only getting one value

I am trying to go through a loop and create a grid that will display all the users found in AD with a couple values such as name, username, password last set and when password expires but i only getting everything on one line.

$ActiveDirectory = New-UDPage -Name "Active Directory" -Icon link -Content {
                $aduser = Get-ADUser -Filter * -Properties *
                $Data = @(
                    @{
                            Name="$($aduser.Name)"
                            Username="$($aduser.samaccountname)"
                            Password_last_Set="$($aduser.Passwordlastset)"
                            Password_Expires="$($aduser.passwordlastset)"
                        } 
                        )
                
                
                $data | ForEach-Object {
                    New-UDGrid -Title 'Active Directory Users' -Headers @("Name", "Username", "Password Last Set", "Password Expires") -Properties @("Name", "Username", "Password_last_Set", "Password_Expires")  -Endpoint {
                        $Data | Out-UDGridData
                    }
                }
                    
        }

Why not just do something like this:

New-UDGrid -title 'Active Directory Users' -Headers @("Name", "Username", "Password Last Set") -endpoint {
    $aduser= Get-ADUser -Filter * -Properties * | select name,samaccountname,passwordlastset
    $aduser | out-UDGridData
}

Note, I haven’t tested this, and I removed ‘Password_Expires’ since it was set equal to the same thing as ‘Password_Last_Set’

2 Likes