D:\NoName\testfolder1\test1.ps1
:
function restapi {
Write-Host "Initiating Rest Call"
$test_value = "1"
}
D:\NoName\Testfolder1\testfolder2\test2.ps1
:
Invoke-Expression -Command D:\NoName\testfolder1\test1.ps1
function Invoke-Rest {
restapi
Write-Host "Invoking rest call and value of test is $test_value"
}
如何调用/导入test1.ps1
文件而不给出完整路径,就像我们在Python中所做的那样:
import testfolder1
from .testfolder1 import test1
PowerShell基本上有两种导入机制:
Module import(通过^{} )使用模块名(如果模块位于
$env:PSModulePath
):或使用完整/相对路径:
Dot-sourcing常规PowerShell脚本,也包含完整或相对路径:
在您的情况下,您可能需要后者:
请注意,automatic variable
$PSScriptRoot
在PowerShell v3之前不可用。在早期版本中,您需要自己确定目录,如下所示:相关问题 更多 >
编程相关推荐