Endpoint Conversion Exception

Product: PowerShell Universal
Version: 1.5.14

Hi @adam

I created a dashboard and an endpoint in PowerShell Universal like so:

$ProcessName = "svchost"

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

    New-UDTypography -Text $Cache:Hello

}

$Schedule = New-UDEndpointSchedule -Every 10 -Second

New-UDEndpoint -Schedule $Schedule -Endpoint {

    $Processes = Get-Process -Name $ArgumentList[0]

    $Cache:Hello = $Processes.Name -join ','

} -ArgumentList $ProcessName

Everything works fine but if I take a look in the Log Section of that particular dashboard I se the following error:

[03-05-21 01:51:41 PM] Waiting for dashboard information... 

[03-05-21 01:51:41 PM] Dashboard information received. Starting dashboard. 

[03-05-21 01:51:41 PM] Creating services. 

[03-05-21 01:51:41 PM] C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3 

[03-05-21 01:51:41 PM] C:\Program Files (x86)\Universal\Cmdlets\Universal.psd1 

[03-05-21 01:51:41 PM] C:\Program Files (x86)\Universal\Microsoft.PowerShell.SecretManagement\0.2.1\Microsoft.PowerShell.SecretManagement.psd1 

[03-05-21 01:51:41 PM] C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.psd1 

[03-05-21 01:51:42 PM] Startup: Cannot convert the "UniversalDashboard.Models.Endpoint" value of type "UniversalDashboard.Models.Endpoint" to type "System.Collections.Hashtable". 

[03-05-21 01:51:42 PM] Startup: at <ScriptBlock>, C:\ProgramData\UniversalAutomation\Repository\Test.ps1: line 8

at <ScriptBlock>, <No file>: line 1 

[03-05-21 01:51:42 PM] Startup:    at System.Management.Automation.LanguagePrimitives.ThrowInvalidCastException(Object valueToConvert, Type resultType)

   at System.Management.Automation.LanguagePrimitives.ConvertNoConversion(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)

   at System.Management.Automation.LanguagePrimitives.ConversionData`1.Invoke(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)

   at System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean recursion, IFormatProvider formatProvider, TypeTable backupTypeTable)

   at System.Management.Automation.Internal.PSDataCollectionStream`1.Write(Object obj, Boolean enumerateCollection)

   at System.Management.Automation.Internal.ObjectStreamBase.Write(Object value)

   at System.Management.Automation.Internal.ObjectWriter.Write(Object obj)

   at System.Management.Automation.Internal.Pipe.AddToPipe(Object obj)

   at System.Management.Automation.Internal.Pipe.Add(Object obj)

   at System.Management.Automation.MshCommandRuntime._WriteObjectSkipAllowCheck(Object sendToPipeline)

   at System.Management.Automation.MshCommandRuntime.WriteObject(Object sendToPipeline)

   at System.Management.Automation.Cmdlet.WriteObject(Object sendToPipeline)

   at UniversalDashboard.Cmdlets.NewEndpointCommand.EndProcessing() in D:\a\universal\universal\src\UniversalDashboard\Cmdlets\NewEndpointCommand.cs:line 86

   at System.Management.Automation.Cmdlet.DoEndProcessing()

   at System.Management.Automation.CommandProcessorBase.Complete() 

[03-05-21 01:51:42 PM] Loading module: C:\Program Files (x86)\Universal\Microsoft.PowerShell.SecretManagement\0.2.1\Microsoft.PowerShell.SecretManagement.psd1 

[03-05-21 01:51:42 PM] Loading module: C:\Program Files (x86)\Universal\Cmdlets\Universal.psd1 

[03-05-21 01:51:42 PM] Loading module: C:\Program Files (x86)\Universal\UniversalDashboard\Frameworks\v3\UniversalDashboard.psd1

Are you aware of that. Just want to let you know.

Greetings
Constantin

Iā€™m getting the same exception.

What happens if you pipe the New-UDEndpoint call to Out-Null?

New-UDEndpoint -Schedule $Schedule -Endpoint {

    $Processes = Get-Process -Name $ArgumentList[0]

    $Cache:Hello = $Processes.Name -join ','

} -ArgumentList $ProcessName | Out-Null
1 Like

Hi @adam,

if I write

$null = New-UDEndpoint -Schedule $Schedule -Endpoint {

    $Processes = Get-Process -Name $ArgumentList[0]

    $Cache:Hello = $Processes.Name -join ','

} -ArgumentList $ProcessName

That brings me no error and also the dashboard works as expected.

Thank you for helping.

This also worked for me. Thanks :slight_smile: