Scheduled powershell script not running dot sourced scripts

Question:

I have a main script that is running other scripts and loading the variables from those scripts using dot sourcing. The script runs fine interactively but when I schedule it to run it does not run the scripts I am dot sourcing. Any ideas?

Answer:

I had a similar problem: My dot sourced scripts didn’t execute when I ran the main script with run as administrator.

It turned out, that the base dir was different, when I ran the script as administrator. Try using the absolute path in your dot sourcing. If it works then, you can work out a better solution, like this:

Source:

Scheduled powershell script not running dot sourced scripts by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply