Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
计划的powershell脚本未运行点源脚本_Powershell - Fatal编程技术网

计划的powershell脚本未运行点源脚本

计划的powershell脚本未运行点源脚本,powershell,Powershell,我有一个主脚本,它运行其他脚本,并使用点源从这些脚本加载变量。该脚本以交互方式运行良好,但当我安排它运行时,它不会运行我正在运行的脚本。有什么想法吗?我有一个类似的问题:当我以管理员身份运行主脚本时,我的点源脚本没有执行 事实证明,当我以管理员身份运行脚本时,base dir是不同的。尝试在点源中使用绝对路径。如果可行,您可以找到更好的解决方案,如下所示: $subScriptName = "MySubscript.ps1" $subScriptPath = Join-Path -Path $c

我有一个主脚本,它运行其他脚本,并使用点源从这些脚本加载变量。该脚本以交互方式运行良好,但当我安排它运行时,它不会运行我正在运行的脚本。有什么想法吗?

我有一个类似的问题:当我以管理员身份运行主脚本时,我的点源脚本没有执行

事实证明,当我以管理员身份运行脚本时,base dir是不同的。尝试在点源中使用绝对路径。如果可行,您可以找到更好的解决方案,如下所示:

$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
}
使用绝对路径


点源是指当前目录。当您以交互方式运行脚本时,此目录通常与脚本相同,但当您计划脚本时,此目录可能是另一个目录。

这正是我想要的。谢谢