Running script on click

Not sure if this is what you are looking or the answer to your issue/question but I got mine to work by creating an Identity under Security, then create and assign new Token to newly created Identity. Then use the token key to connect to the PSUServer and then call UAScript. Example code below of how is use it. My example below will display on-demand output from the running script into a code editor element.

$AppToken = 'YOUR_TOKEN_HERE'
Connect-PSUServer -ComputerName http://localhost:5000 -AppToken $AppToken

$Job = Invoke-UAScript -Script 'Test.ps1' -service "$Session:svc" -srvname $Session:server -operator $Session:userinfo.displayName

        while($Job.Status -ne 'Completed')
        {
            Start-Sleep 1
            $Output = (Get-UAJobOutput -Job $Job).Data -join ([Environment]::NewLine)
            Set-UDElement -Id 'codeEditor' -Properties @{
                code = $Output
            }

            $Job = Get-UAJob -Id $Job.Id
        }

Get live output from running script reference post