M7 发帖数: 219 | 1 I have two scripts, A.ps1 is the main function and B.ps1 has all the
functions that A.ps1 calls. Both scripts are in the same folder.
To put B into A’s scope, I tried to put the following in A.ps1
. .\B.ps1
With the above statement, or I put the path in single or double quotes, I
always get this error message:
The term '.\B.ps1' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
If I use the absolute path, the script runs smoothly.
. C:\Users\xyz\Desktop\B.ps1
Any clue what is wrong?
Thanks a lot! | t*****s 发帖数: 124 | 2 解决依赖问题在PowerShell 2.0里可以用Module
可参考 http://msdn.microsoft.com/en-us/library/dd878310(v=vs.85).aspx
如果非要用dot source的话,在A.ps1里加入
$myPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. $myPath/relativePathToB/B.ps1
【在 M7 的大作中提到】 : I have two scripts, A.ps1 is the main function and B.ps1 has all the : functions that A.ps1 calls. Both scripts are in the same folder. : To put B into A’s scope, I tried to put the following in A.ps1 : . .\B.ps1 : With the above statement, or I put the path in single or double quotes, I : always get this error message: : The term '.\B.ps1' is not recognized as the name of a cmdlet, function, : script file, or operable program. Check the spelling of the name, or if a : path was included, verify that the path is correct and try again. : If I use the absolute path, the script runs smoothly.
|
|