Hi there, just having trouble trying to create a proof of concept site that has a simple button that invokes a script in UA; following the “Active Directory Help Desk” blog examples I’m trying…
New-UDButton -Text 'Run UA script' -Id 'btnRunScript' -OnClick {
Show-UDToast -Message "starting run UA script" -Duration 5000
#Invoke-UAScript -Id 2 -AppToken $apptoken | Tee-Object -Variable Job | Wait-UAJob
#Invoke-UAScript -Name 'Get-Subscribers.ps1' -AppToken $apptoken | Tee-Object -Variable Job | Wait-UAJob
Invoke-UAScript -Name 'Get-Subscribers.ps1' | Tee-Object -Variable Job | Wait-UAJob
$getJob = Get-UAJob -Id $Job.Id
Show-UDToast -Message "job id is: $($getJob.Id)"
If ($getJob.Status -eq 'Completed') {
Show-UDToast -Message "job completed ok" -Duration 5000
} else {
$Output = Get-UAJobOutput -JobId $Job.Id | Select-Object -Expand Message
Show-UDToast -Message "job failed $($Output -join "`n")" -Duration 5000 -BackgroundColor Red -MessageColor white
}
}
It just doesn’t seem to work, I’ve tried with apptokens too, I get no valid response/data in the toasts.
If I run Get-UAJob or Invoke-UAScript from a PowerShell prompt, I get…
PS > Get-UAJob -Id 2
Get-UAJob : Call failed with status code 401 (Unauthorized): GET https://servername/api/v1/Job/2
At line:1 char:1
+ Get-UAJob -Id 2
**+ ~~~~~~~~~~~~~~~**
** + CategoryInfo : NotSpecified: ( [Get-UAJob], FlurlHttpException**
** + FullyQualifiedErrorId : Flurl.Http.FlurlHttpException,UniversalAutomation.GetJobCommand**
or…
PS > Invoke-UAScript -Name 'Get-Subscribers.ps1’
Invoke-UAScript : Cannot retrieve the dynamic parameters for the cmdlet. Call failed with status code 401
(Unauthorized): GET https://servername/api/v1/Script/Get-Subscribers.ps1
But when I throw this into a browser: https://servername/api/v1/Job/2 I get a response, like…
{“id”:2,“createdTime”:“2020-08-07T09:29:43.91+12:00”,“startTime”:“2020-08-07T09:29:43.988+12:00”,“endTime”:“2020-08-07T09:29:46.13+12:00”,“status”:2,“output”:null,“script”:{“id”:2,“name”:null,“description”:null,“createdTime”:“0001-01-01T00:00:00”,“manualTime”:0.0,“commitId”:null,“content”:null,“scriptParameters”:null,“identity”:null,“tags”:null,“schedules”:null,“status”:0,“folder”:null,“fullPath”:null,“requiredPowerShellVersion”:null,“errorAction”:0,“informationAction”:0,“verbose”:false,“debug”:false,“commitNotes”:null,“disableManualInvocation”:false,“maxHistory”:100},“scriptCommitId”:null,“appToken”:{“id”:2,“token”:null,“identity”:null,“revoked”:false,“role”:null,“created”:“0001-01-01T00:00:00”,“expiration”:“0001-01-01T00:00:00”,“revokedDate”:“0001-01-01T00:00:00”},“identity”:{“id”:1,“name”:“Admin”,“source”:0,“role”:null},“parentJob”:null,“parentLineNumber”:0,“debug”:false,“computerName”:“localhost”,“port”:56976,“processId”:12900,“runspaceId”:2,“activity”:“Preparing modules for first use.”,“currentOperation”:null,“percentComplete”:-1,“secondsRemaining”:-1,“statusDescription”:null,“powerShellVersion”:" 5.1.14393.3471",“agent”:null,“computer”:{“id”:1,“name”:null},“errorAction”:0,“children”:null,“jobOutput”:null,“parameters”:null,“notes”:null,“credential”:null}
or likewise with this https://servername/api/v1/Script/Get-Subscribers.ps1…
{“id”:2,“name”:“Get-Subscribers.ps1”,“description”:null,“createdTime”:“2020-08-07T09:20:22.241+12:00”,“manualTime”:0.0,“commitId”:null,“content”:"# Get-Subscribers\r\nGet-Process | Where-Object {$_.Name -like “m*”}",“scriptParameters”:null,“identity”:{“id”:1,“name”:null,“source”:0,“role”:null},“tags”:[],“schedules”:null,“status”:0,“folder”:null,“fullPath”:“Get-Subscribers.ps1”,“requiredPowerShellVersion”:null,“errorAction”:0,“informationAction”:2,“verbose”:false,“debug”:false,“commitNotes”:null,“disableManualInvocation”:false,“maxHistory”:100}
Update:
If I connect with the -AppTOken first, then Get-UAJob and Invoke-UAScript work
PS > Connect-UAServer -ComputerName https://servername -AppToken 'JhbGciOi…1SFADhUuyTq4_G’
PS > Get-UAJob -Id 2
Id : 2
CreatedTime : 7/08/2020 9:29:43 AM
StartTime : 7/08/2020 9:29:43 AM
EndTime : 7/08/2020 9:29:46 AM
Status : Completed
Output :
Script :
(With a new job added to the list of jobs in UA after Invoke-UAScript -Id 2)
I feel like it’s so close, just something silly I’m missing. Maybe somehow setting an AppToken for the dashboard when it is started?
Would really appreciate the help! (note: I’m running from IIS, and have tried with Windows auth off and on, which is working when on, I can show $user and $roles in the dashboard)
Cheers,
Steve.