Scheduled powershell script does not run point subscription scripts

I have a main script that runs other scripts and loads variables from these scripts using a point source. The script works fine interactively, but when I plan to run it, it does not run scripts, I am an exact search. Any ideas?

+4
source share
2 answers

I had a similar problem: the scripts with my points did not execute when I ran the main script and run as administrator.

It turned out that the underlying dir was different when I ran the script as an administrator. Try to use the absolute path in the search for points. If it works, you can find a better solution, for example:

$subScriptName = "MySubscript.ps1" $subScriptPath = Join-Path -Path $callingDir -ChildPath $subScriptName if (Test-Path $subScriptPath) { # use file from local folder . $subScriptPath } else { # use central file (via PATH-Variable) . $subScriptName } 
+6
source

Use absolute paths.

Dot sourcing refers to the current directory. This is usually the same directory as your script when you run interactively, but may be a different directory when planning the script.

0
source

Source: https://habr.com/ru/post/1314953/


All Articles