点源失败oin powergui

Mic*_*per 2 powershell powergui

我试图在PowerGui 3.0中点源脚本文件,但我得到的只是;


术语".\ PowerShell.Common.ps1"未被识别为cmdlet,函数,脚本文件或可操作程序的名称.检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试.在D:\ TFS\SharePoint\Dev\Deploy\AutoSPInstaller\SP2010\AutoSPInstaller\AutoSPInstallerFunctionsCustom.ps1:6 char:31 +.\.PowerShell.Common.ps1 <<<< + CategoryInfo:ObjectNotFound:(.\ PowerShell.Common. ps1:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException


并且powerGui随后不在所述文件中提供我的脚本功能 - 在父脚本的上下文敏感列表中.

文件"PowerShell.Common.ps1"与AutoSPInstallerFunctionsCustom.ps1位于同一目录中.感谢您的帮助

Ryn*_*ant 5

要从PowerGUI的命令行对源文件进行点源,请确保当前的工作目录位于脚本的目录中.您可以通过$PWD在PowerGUI的命令行输入来检查这一点.

要从脚本引用另一个脚本,您可以这样做:

# Get the current script's directory
$MyDir = Split-Path $MyInvocation.MyCommand.Definition

# Dot-source the external script by using the current script's directory
. "$MyDir\ScriptName.ps1"
Run Code Online (Sandbox Code Playgroud)

获取脚本的目录可确保即使您当前的工作目录与脚本的目录不同,您也可以引用相对于脚本位置的文件.