Run schedluled script at PU start

Product: PowerShell Universal
Version: 4.2.13

I have a script that creates a bunch of cache variables from our AD that i later use on my applications.
It executes in around 2 minuets
I created a schedule that is executed in background every hour.
And it runs perfectly - it speed up page loading time a lot (i don’t have to read it form AD every time when its needed on application)

But here is the catch.
Sometimes i need to restart server or just PU itself (service).
And then i have to remember to manually trigger this script (or wait for full hour to run according to schedule)

I noticed that Schedule have cron expression setting - but how to set up it to run after PU has stared (with some delay for safety ?) in linux there is a @reboot expression for cron but im not sure it will work here

So is it achievable by cron in PU ?
If not, is there a chance to add this setting (to run after PU starts) to PU Schedule in future versions ?

besides schedules, Scripts can be executed after a trigger has fired. this includes an “Server Started” trigger.


Thanks i think it should work.

But I have bigger problem.

As i said in this script i read bunch of data (mostly users account) and store them in cache variable
And basically its working those users ale in good variables.
But im able only to read default properties of those users (like Enabled,GivenName,Name,ObjectClass,ObjectGUID,SamAccountName,SID,Surname,UserPrincipalName)

But i want to read some other proprieties like mail, description and others

And it is not populated

When I add the same code to the app code - its working , on the scheduled script its not

What im missing ?

sounds like the default properties of Get-ADuser

Additional properties can be returned using the -properties argument

Like -Properties * to return all properties, but its best to limit data to only whats neccesary.

Get-Aduser $user -properties mail,Description

im maybe doing sometime stupid mistakes but not that simple ones.
of course im using -Properties for Get-ADUser.
and the same line of code returns only default fields when executing from script and all wanted fields when launched from dashboard/page
if someone ask im using integrated environment for both script and dashboards

Feel free to share any code that might aid us in helping. :slight_smile:

its to big to share
basicly its smoething like that:

$cache:svc_ad_users = Get-ADUser -Filter {Enabled -eq $true} -SearchBase $ou -Properties AccountExpirationDate,info,Description 

$cache:ad_users = (Get-ADUser -Filter {name -notlike "*.id"} -SearchBase $user_ou -Properties description,mail,DisplayName,EnCn,UserClassify,L,EmployeeNumber 

i deleted some confidential fields and information (like ad controller names) but i think its not the point,

but the things got little stranger that i thought.

If I add this line

$cache:ad_users = (Get-ADUser -Filter {name -notlike "*.id"} -SearchBase $user_ou -Properties description,mail,DisplayName,EnCn,UserClassify,L,EmployeeNumber 

to the dashboard code, everything is working (i can read extended properties from both regular and svc users)

It was working that way for a long time but i decided to add some new variables (like groups etc) and it caused that dashboard loading time has increased.

But when its missing nothing works from extended properties (for both regular and svc users)

I made somewhere a mistake but i cant figure it out what it might be…