Running Script on Schedules

Product: PowerShell Universal
Version: 5.1.2

Hello,

it’s me, again.

Currently, we are trying to integrate an assessment script into PowerShell Universal. This script is supposed to assess data from our internal AD and then write it to the PowerShell Universal Cache so that this information can be displayed in an app.

The cache is written in the script with the following command:

Set-PSUCache -Key "Overview_Data" -Value $OutputTable -AbsoluteExpirationFromNow([TimeSpan]::FromHours(1)) -TrustCertificate:$True

The script runs in the context of a user with the appropriate rights. When executed manually, everything works fine. However, when we try to start the script via a schedule, it always results in the following error:

Unauthenticated. Specify an app token, use default credentials, or enable permissive security model.

Our solution approach was to use an app token. If we include this as a string in the script, it also works. However, if we try to store the app token as a PowerShell Universal Secret (Secret String) and then call it in the script with

$Secret:AppToken

we get the aforementioned error again. After some debugging, we found that the secret remains empty when called through automation. This also happens when we run the schedule in the context of the same user (as with the script).

What are we doing wrong?

1 Like

I am having the same error when scheduling a script in the line that gets a psu script
$Script = Get-PSUScript -Name “XXX”

It is working when I invoke a script directly but if I schedule the script, it returns the error:
Unauthenticated. Specify an app token, use default credentials, or enable permissive security model.

Any help is appreciated. thanks

You will need to either specify an app token or use the -Integrated security model.

Well yes, but we want to safe the app token as a secret and use said secret. But using the secret with the scedule doesnt work, even if we let it run in the context of a user with the right permissions. Do we realy have to safe the app token in the script?

If you have roles applied to the secret, then the scheduled job won’t have access because when it is running there is no user roles assigned.

If you remove the roles, it should be accessible in the schedule.

1 Like