【发布时间】:2019-09-19 09:17:05
【问题描述】:
using module 和$PSScriptRoot 如何使用?
using module $PSScriptRoot/../myfolder/base.psm1
# or: using module "$PSScriptRoot/../myfolder/base.psm1"
如果我这样做,我会得到这个错误:
using module $PSScriptRoot: is not a valid value for using name
感谢@DavidBrabant,我尝试了以下方法:
$scriptBody = "using module /Users/name/Development/tools/powershell/base/base.psm1"
$script = [ScriptBlock]::Create($scriptBody)
. $script
Class Go : MyBaseClass {
...
不幸的是我得到了:
Unable to find type [MyBaseClass].PowerShell
Ignoring 'TypeNotFound' parse error on type 'MyBaseClass'. Check if the specified type is correct. This can also be due the type not being known at parse time due to types
感谢@MathiasR.Jessen,我尝试使用“\”得到相同的结果。如果这有什么不同,我应该说我使用的是 Mac 电脑。
【问题讨论】:
-
使用模块语句不能包含任何变量。它的值必须是静态的。有一种解决方法。见这里:info.sapien.com/index.php/scripting/scripting-classes/…
-
using module指令doesn't seem to respect/as a path separator,试试using module $PSScriptRoot\..\myfolder\base.psm1或using module ..\myfolder\base.psm1
标签: powershell powershell-module