A few issues with UniversalDashboard.SQL

Hi,

I am trying the New-UDSQLTable to display some results from our SQL. It can display the result on the dashboard successfully. However, I always get this error message when I load the result on the page:
AM An error occurred: Cannot bind argument to parameter ‘InputObject’ because it is null.

What does this mean?

I have also found that the page count is incorrect. I have some “where” clauses inside the sql query. But when I check out the page, it shows the total page count from the whole sql table. How can I set it correctly?

And the last question, is there a way I can set the display all results instead of 5 rows per page?

Thanks so much!

Here is my code:

New-UDDashboard -Title "Hello, World!" -Content {

New-UDTypography -Text "Hello, World!"

$Parameters = @{

   Title = "Test"

   Query = "SELECT        AssignmentName, DeviceName, LastComplianceMessageDesc, LastComplianceMessageTime, LastEnforcementMessageTime, LastEnforcementMessageDesc, 

                     CASE LastEnforcementErrorCode WHEN '0' THEN 'Success' WHEN '-2016409844' THEN 'Software update execution timeout' WHEN '-2016409966' THEN 'Group policy conflict' WHEN '-2016410008' THEN 'Software update still detected as actionable after apply'

                      WHEN '-2016410012' THEN 'Updates handler job was cancelled' WHEN '-2016410026' THEN 'Updates handler was unable to continue due to some generic internal error' WHEN '-2016410031' THEN 'Post install scan failed'

                      WHEN '-2016410032' THEN 'Pre install scan failed' WHEN '-2016410855' THEN 'Unknown error' WHEN '-2016411012' THEN 'CI documents download timed out' WHEN '-2016411115' THEN 'Item not found' WHEN

                      '-2145107951' THEN 'WUServer policy value is missing in the registry.' WHEN '-2145120257' THEN 'An operation failed due to reasons not covered by another error code.' WHEN '-2145123272' THEN 'There is no route or network connectivity to the endpoint.'

                      WHEN '-2145124320' THEN 'Operation did not complete because there is no logged-on interactive user.' WHEN '-2145124341' THEN 'Operation was cancelled.' WHEN '-2146498304' THEN 'Unknown error' WHEN

                      '-2146762496' THEN 'No signature was present in the subject.' WHEN '-2146889721' THEN 'The hash value is not correct.' WHEN '-2147010798' THEN 'The component store has been corrupted.' WHEN '-2147010815'

                      THEN 'The referenced assembly could not be found.' WHEN '-2147010893' THEN 'The referenced assembly is not installed on your system.' WHEN '-2147018095' THEN 'Transaction support within the specified resource manager is not started or was shut down due to an error.'

                      WHEN '-2147021879' THEN 'The requested operation failed. A system reboot is required to roll back changes made.' WHEN '-2147023436' THEN 'This operation returned because the timeout period expired.' WHEN

                      '-2147023728' THEN 'Element not found.' WHEN '-2147023890' THEN 'The volume for a file has been externally altered so that the opened file is no longer valid.' WHEN '-2147024598' THEN 'Too many posts were made to a semaphore.'

                      WHEN '-2147024784' THEN 'There is not enough space on the disk.' WHEN '-2147217865' THEN 'Unknown error' WHEN '-2147467259' THEN 'Unspecified error' WHEN '-2147467260' THEN 'Operation aborted' ELSE

                      'Pending Reboot' END AS 'Last Message'

FROM            dbo.vSMS_SUMDeploymentStatusPerAsset

WHERE        (AssignmentName = N'internalpatch') AND (LastComplianceMessageDesc = N'Non-compliant')

"

   CountQuery = "SELECT COUNT(*) as Count FROM dbo.vSMS_SUMDeploymentStatusPerAsset"

   Columns = @( "DeviceName", "LastComplianceMessageTime", "LastEnforcementMessageDesc", "Last Message")

   SqlInstance = "XXX"

   Database = "CM_XXX"

   }

   New-UDSQLTable @Parameters

}

Hello @qy2009 and welcome to the forums…ok so my first question is do you have the dbatools installed? https://dbatools.io/ As I see you need this installed for the component to work. I mean you have quite a few questions, you do realise that you can easily load SQL data into like any of the components or custom components out there. I mean I have personally not used this custom component, as I can load SQL data into the standard PSU table or another custom component table I got various examples on my blog site here:- UDFLIX a Blogtastic Site

Hi @psDevUK I did install the dbatools, otherwise I won’t get the sql result from the output page I think :slight_smile: you are right, I think I will try other components and see if others will work. I use UniversalDashboard.SQL because it’s simple and saves some time .

Hello @qy2009 ok so as mentioned I have not tried this add-on yet. I did try looking for documentation on it, but sadly I couldn’t find any, so I know @adam does a sterling job on documentation, so I have now tagged Adam to enlighten both of us if there is documentation for this. Having skimmed through your SQL query I see a lot of CASE WHEN, which is no issue, but I am wondering if you run this in SSMS do you get any null results in your query table?

Hi @psDevUK , I saw the last row is NULL, not sure that was the issue? In my data, “LastEnforcementErrorCode” rows have some data that is null, so I have set up this type of data in my “else” clause. Am I doing it wrong?

On another note, I have just used the New-UDTable, and it can display my data correctly without the case:

    Import-Module dbatools
    $sqlserver = 'xxx'
    $database = 'xxx'
    $query = @"
  SELECT AssignmentName, DeviceName, LastComplianceMessageDesc, LastComplianceMessageTime, LastEnforcementMessageTime, LastEnforcementMessageDesc, LastEnforcementErrorCode
  FROM dbo.vSMS_SUMDeploymentStatusPerAsset
  "@
       $Patching = Invoke-DbaQuery -SqlInstance $sqlserver -Database $database -Query $query | Select-Object AssignmentName, DeviceName, LastComplianceMessageDesc, LastComplianceMessageTime, LastEnforcementMessageTime, LastEnforcementMessageDesc
   New-UDTable -Data $Patching

If I am using the CASE WHEN, then it will error out.

I have also tried using " New-UdGrid". I read from your blog that this is the one you recommend?
However, even if I execute this simple command, it failed. I wonder why?

New-UdGrid -Title "Processes" {
Get-Process | Select Name,ID,WorkingSet,CPU | Out-UDGridData

I got the message that “Parameter set cannot be resolved using the specified named parameters”

Thanks so much for your help :slight_smile:

New-UDGrid was a cmdlet in UD v2.9.

What’s the output look like in PS when you run the CASE WHEN query?

@adam, ah. no wonder, I am using UD v3.5.0.
If I run the CASH WHEN query directly in PS, the output is totally fine:

test

Does it behave differently if you use expressions with Select-Object and turn the properties to strings? I know we have some issues with Select-Object and APIs returning blank property values.

    Import-Module dbatools
    $sqlserver = 'xxx'
    $database = 'xxx'
    $query = @"
  SELECT AssignmentName, DeviceName, LastComplianceMessageDesc, LastComplianceMessageTime, LastEnforcementMessageTime, LastEnforcementMessageDesc, LastEnforcementErrorCode
  FROM dbo.vSMS_SUMDeploymentStatusPerAsset
  "@
       $Patching = Invoke-DbaQuery -SqlInstance $sqlserver -Database $database -Query $query | Select-Object @{n='AssignmentName'; e={$_.AssignmentName.ToString()},@{n='DeviceName'; e={$_.DeviceName.ToString()} #, LastComplianceMessageDesc, LastComplianceMessageTime, LastEnforcementMessageTime, LastEnforcementMessageDesc
   New-UDTable -Data $Patching

@adam Is there a typo in the code? I tried the one above, and tried :
@{n=‘DeviceName’; e={$_.DeviceName.ToString()}}
but both got “One or more errors occurred”.
when I checked the log, it said "Unexpected token ‘}’ in expression or statement. "

Yep. Sorry about that. It was missing closing braces.

    Import-Module dbatools
    $sqlserver = 'xxx'
    $database = 'xxx'
    $query = @"
  SELECT AssignmentName, DeviceName, LastComplianceMessageDesc, LastComplianceMessageTime, LastEnforcementMessageTime, LastEnforcementMessageDesc, LastEnforcementErrorCode
  FROM dbo.vSMS_SUMDeploymentStatusPerAsset
  "@
       $Patching = Invoke-DbaQuery -SqlInstance $sqlserver -Database $database -Query $query | Select-Object @{n='AssignmentName'; e={$_.AssignmentName.ToString()}},@{n='DeviceName'; e={$_.DeviceName.ToString()}} #, LastComplianceMessageDesc, LastComplianceMessageTime, LastEnforcementMessageTime, LastEnforcementMessageDesc
   New-UDTable -Data $Patching

@adam I tried that as well. also failed with same reason :frowning:

Hmmm must still be a typo or something. I tried executing it locally and it works in the PS prompt.

@adam it looks like not typo, but some data errors? When I ran from PS, I got this result from this pic

But if I just run the original script from PS, the output is fine.

where did it go wrong? some null data inside?

That’s what I’m not really sure about. Based on the output, it looks like it’s failing to query the data correctly but I don’t know why that would only happen when the select-object was changed.

I know originally, in this post you were trying to supress the error from being show. We now have a switch to disable that toast message: Dashboards - PowerShell Universal