Unable to Get-UAScript

Hi,

I’m trying to get result from a script with templates given (Computer Reports.ps1 to begin) and even if the job are successfull and with results, i’m unable to Get-UAScript in Universal Dashboard.

I’ve tried to Connect-UAserver before but no luck … :sob:

Connect-UAServer -ComputerName "http://localhost:5000" -Credential $Credential

$LatestComputerReport = Get-UAScript -Name 'Computer Report.ps1' | Get-UAJob -OrderBy Id -OrderDirection Descending -First 1 | Get-UAJobPipelineOutput

Have you some ideas please ?

I’ve tried manually, again there is something i’m doing wrong :

Connect-UAServer -ComputerName "http://localhost:5000"

Get-UAScript -Name "Computer Report.ps1"
Call failed. An error occurred while sending the request. GET http://localhost:5000/api/v1/Script/Computer%20Report.ps1
    + CategoryInfo          : NotSpecified: (:) [Get-UAScript], FlurlHttpException
    + FullyQualifiedErrorId : Flurl.Http.FlurlHttpException,UniversalAutomation.GetScriptCommand

By the way, the -Credential parameter doesn’t seem to work manually

Connect-PSUServer : A parameter cannot be found that matches parameter name 'Credential'.
At line:1 char:56
+ ... ct-UAServer -ComputerName "http://localhost:5000" -Credential (get-cr ...
+                                                       ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Connect-PSUServer], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,UniversalAutomation.ConnectServerCommand

… but is required on the dashboard :

#LOG FROM DASHBOARD ON WEB ADMIN INTERFACE (when no credential is provided)
[07-24-20 10:11:01 AM] PS: Call failed with status code 401 (Unauthorized): GET http://localhost:5000/api/v1/Script/Computer%20Report.ps1

You will need an app token to call the web api: https://docs.ironmansoftware.com/config/management-api#app-tokens

1 Like

Thanks, i’ll take a look !

Is there is another way to get results from jobs or scripts than a web api and its associated token ?

EDIT : With -AppToken i get this error Index was outside the bounds of the array
I try to understand where this come from (maybe here Index was outside the bounds of the array )

As far as i know it is somewhere here :

    $LastTenComputerReports = Get-UAScript -Name 'Computer Report.ps1' | Get-UAJob -OrderBy Id -OrderDirection Ascending -First 25 | Get-UAJobPipelineOutput
	
    $Data = @()
    foreach($jobOutput in $LastTenComputerReports)
    {
        $Location = $jobOutput.Location
        
        $record = @{}
        $Location | ForEach-Object {
            if ($_.Label -ne $null) 
            {
                $record[$_.Label.Split(',')[0]] = [int]$_.Value
            }
        }
        if ($record.Count -ne 0)
        {
            $Data += $record
        }
    }
    
    New-UDNivoChart -Stream -Data $Data -Height 500 -Responsive -Keys @('hailey', 'madison')

If i try to output the value of Data (for 3000 computers) :

Name                           Value
----                           -----
                               4771
                               4771
                               4771

Maybe it is because the Location attribute isn’t populated in this forest …

Yep! That would be the problem. It’s attempting to show a chart based on locations in the forest. If you remove the foreach all together, it shouldn’t cause that issue

Thanks for the answer.
You already give me a solution in your previous post :partying_face:

The Computer Report.ps1 allow me to discover the way it works (and it works great !).

It is certainly not my last post :innocent: but i can try to publish a dashboard to my co-workers now ^^

1 Like