Grid, No record found

when I run this, i get no record found, any idea why?

$Rst=@()
$allproc=Get-Process
$allproc | ForEach-Object {
$Rst += [PSCustomObject]@{

        Name =  $_.Name

        ID= $_.Id
    }
}

$Dashboard = New-UDDashboard -Title “DashBoard” -Content {

New-UdGrid -Title "Processes" -Endpoint {
    $Rst | Select-Object Name,ID | Out-UDGridData
}

}

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Dashboard $Dashboard -Port 8080

any idea why it is not working?.

New-udgrid is a new endpoint. This is like a new powershell session (runspace).
If you want to use variables in it, you must declare it in the endpoint Or you declare it as $cache:rst variables (must be happen in the inner dashboard code - I think) .
If you are using a US Dashboard version before 2.4 you also have to define more parameters (header + 1 I forgot) for the grid.

Is there an example?

this worked
$LandingPage = New-UDPage -Name “Grids” -Icon bar_chart -Content {
New-UDGrid -Title “Process” -Headers @(“Name”, “id”) -Properties @(“Name”, “id”) -Endpoint {
Data = @( Get-Process | Select-Object Name, Id | ForEach-Object { [PSCustomObject]@{Name=.Name ; id=$.Id}
}
)
$Data | Out-UDGridData
}
}
$Dashboard = New-UDDashboard -Title “Grid Test” -Pages @(
$LandingPage
)

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Dashboard $Dashboard -Port 8080

looks similar to the example I posted :grin: for someone else, glad you got it working, take time to read the annoucements adam makes as he talks about variables not displaying how you think in his latest blog post. Sorry I missed this post 10 days ago doh!

I think you answered me. It really worked in one environmnet,however on my laptop still same behaviour.

I am now trying to pull data from DB, and the page is not loading, here is my code:

Import-Module UniversalDashboard
Get-UDDashboard | Stop-UDDashboard

$LandingPage = New-UDPage -Name “Grids” -Icon bar_chart -Content {
New-UDGrid -Title “Process” -Headers @(“ID”) -Properties @(“ID”) -Endpoint {
$Data = @(
$orchestratorInstance = “orchestratordb-int,3187”
$orchestratorDBName = “Opalisint2016”
$q = @’
select top 1 ID from [Microsoft.SystemCenter.Orchestrator].[Runbooks]
'@
$r = Invoke-Sqlcmd -ServerInstance $orchestratorInstance -Database $orchestratorDBName -Query $q
$r
)
$Data | Out-UDGridData
}
}
$Dashboard = New-UDDashboard -Title “Grid Test123” -Pages @(
$LandingPage
)

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Dashboard $Dashboard -Port 8080

Do you have any idea why the results is not loading, and the powershell session is starting with kind of memory leak?

Thanks!

my here strings are @" "@ I see your using single quotes? Also looks like you putting evertyhing into an array with the $Data variable, not sure this would even work in an ISE session, have you tried that? Give me a quick moment and I will build a simple dashboard and show you how to make use of the end-point…2 moments i’ll be back


Just about to post this on github give me a moment…here you go my friend:-

1 Like

@psDevUK
Thank you so much, it is working now!!!

awesome to hear @shykhovtsov glad I could help :grin:

this worked for me for quering mysql db and display on grid
$global:DBServerGlobal= “DC07INVDBVW1.domain.local”
$Global:usernameGlobal = “Domain\svc” # User account with permissions to the server
$Global:passwordGlobal = “mypassword!” | ConvertTo-SecureString -asPlainText -Force
$Global:credentialGlobal = New-Object System.Management.Automation.PSCredential($usernameGlobal, $passwordGlobal)

function UDQueryMySQLDB
{
[CmdletBinding()]
Param (
[Parameter(
Mandatory = $true,
ParameterSetName = ‘’,
ValueFromPipeline = $true)]
[string]$Query
)

$MySQLAdminUserName = 'MySQLUserName'
$MySQLAdminPassword = 'mySQLPassword'
$MySQLDatabase = 'assetmanagement'
$MySQLHost = 'DC07INVDBVW1'
$ConnectionString = "server=" + $MySQLHost + ";port=3306;uid=" + $MySQLAdminUserName + ";pwd=" + $MySQLAdminPassword + ";database=" + $MySQLDatabase

Try
{
	[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
	$Connection = New-Object MySql.Data.MySqlClient.MySqlConnection
	$Connection.ConnectionString = $ConnectionString
	$Connection.Open()
	
	$Command = New-Object MySql.Data.MySqlClient.MySqlCommand($Query, $Connection)
	$DataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($Command)
	$DataSet = New-Object System.Data.DataSet
	$RecordCount = $dataAdapter.Fill($dataSet, "data")
	$AllItems = $DataSet.Tables[0]
	Return $AllItems
	
}

Catch
{
	Write-Host "ERROR : Unable to run query : $query `n$Error[0]"
}

Finally
{
	$Connection.Close()
}

}

$session = New-PSSession -credential $credentialGlobal -ComputerName $DBServerGlobal

$queryActive = @"
SELECT productname FROM assetmanagement.serverinventory WHERE 1=1 And ((Team=‘Police’) or (Team=‘Wes Team’) or
(Team=‘FourStar’)) AND (OS like’%Windows%’ OR OS= ‘VSPHERE ESXi’ OR OS=‘EMC SAN’) AND ProductAssetType=‘Server’ And
(ServiceStatus =‘Active’) ORDER BY productname ASC, Status ASC
"@

$Cache:ActiveV = Invoke-Command -session session -ScriptBlock {function:UDQueryMySQLDB} -ArgumentList $queryActive

$LandingPage = New-UDPage -Name “Grids” -Icon bar_chart -Content {
New-UDGrid -Title “Process” -Headers @(“productname”) -Properties @(“productname”) -Endpoint {
$Cache:ActiveV | Select-Object “productname” | Out-UDGridData
}
}
$Dashboard = New-UDDashboard -Title “Grid Test” -Pages @(
$LandingPage
)

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Dashboard $Dashboard -Port 8080