Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behaviour when sending a PSCustomObject with PSCredentials from a Dashboard to a PSUScript using Invoke-PSUScript #4317

Open
chauberg opened this issue Jan 31, 2025 · 1 comment
Labels
requires triage Issue has not yet been verified by the development team. v5 Version 5 issue.

Comments

@chauberg
Copy link

chauberg commented Jan 31, 2025

Description of Issue

I have a dashboard where I define a settings variable which is a PSCustomObject with some PSCredential variables inside, this is used in the dashboard for some function calls and then sent to a PSUScript using Invoke-PSUScript - the issue I'm having is that this works correctly sometimes (usually after a Dashboard restart) and then randomly fails, it seems like the types get wonky randomly.

I made the following test setup to replicate the issue:
Dashboard

function CallScript
{
    param ([PSCustomObject]$Settings)

    $scriptParameters = @{
        Settings = $Settings
    }
    Invoke-PSUScript -Script (Get-PSUScript -Name "TestCred.ps1") @scriptParameters | Tee-Object -Variable job | Wait-PSUJob
    $result = Get-PSUJobPipelineOutput -Job $job
    Write-Host $result
}

New-UDApp -Content {
    [PSCustomObject]$test = @{
        TestCredential = $Secret:PsCredentialTest
    }

    New-UDForm -Id "Form" -Content {} -OnSubmit {
        CallScript -Settings $test
    }
}

TestCred.ps1

param (
    [Parameter(Mandatory)]
    [PSCustomObject]
    [ValidateScript({
        function Validate
        {
            param (
                [Parameter(Mandatory)]
                [PSCredential]
                $TestCredential
            )
            return $true
        }
        $settings = $_
        Validate @settings
    })]
    $Settings
    )

Write-Host ($Settings | ConvertTo-Json)

I use a ValidateScript parameter in the script to ensure that the credential is passed properly.

As I type this I've clicked the submit button in the dashboard a couple of times where it has randomly succeeded the validation and also failed without me changing anything in the dashboard or the script.

Image

I'm at a loss here, please help :D

Version

5.2.1

Severity

Medium

Hosting Method

MSI (Windows Service)

Operating System

Windows

Database

SQL

Licensed

Yes

Features

No response

Additional Environment data

No response

Screenshots/Animations

No response

@chauberg chauberg added requires triage Issue has not yet been verified by the development team. v5 Version 5 issue. labels Jan 31, 2025
@chauberg
Copy link
Author

chauberg commented Feb 4, 2025

Note that I am actually using a hashtable, not a PSCustomObject as the latter doesn't seem to play nice with splatting but it doesn't change the underlying issue, it seems that often the PSCredentials are delivered as a different type "System.Management.Automation.PSObject" instead of PSCredential which bricks the validation.. I made a function that iterates over my hashtable and casts properties to PSCredential inside the PSUScript before passing it into the function with validation as a hacky solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires triage Issue has not yet been verified by the development team. v5 Version 5 issue.
Projects
None yet
Development

No branches or pull requests

1 participant