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 能否从ps1文件中加载ps1文件?_Powershell - Fatal编程技术网

Powershell 能否从ps1文件中加载ps1文件?

Powershell 能否从ps1文件中加载ps1文件?,powershell,Powershell,我可以从ps1文件中加载ps1文件吗 最终的目标是制作一个ps1文件,我把它放在我所有计算机上的配置文件中,并且有一个浮动配置文件,我可以把pocket实用程序的路径放在其中。 我可能会将其放入代码回购或某种外部共享机制中。这在powershell中得到了最明确的支持,我的机器上也有完全相同的设置 标准配置文件.ps1内容 . ~\winconfig\PowerShell\Profile.ps1 WinConfig\PowerShell中的Profile.ps1是我的版本控制配置文件,其中包含

我可以从ps1文件中加载ps1文件吗

最终的目标是制作一个ps1文件,我把它放在我所有计算机上的配置文件中,并且有一个浮动配置文件,我可以把pocket实用程序的路径放在其中。
我可能会将其放入代码回购或某种外部共享机制中。

这在powershell中得到了最明确的支持,我的机器上也有完全相同的设置

标准配置文件.ps1内容

. ~\winconfig\PowerShell\Profile.ps1

WinConfig\PowerShell中的Profile.ps1是我的版本控制配置文件,其中包含我所有的自定义乐趣。我有一个脚本,只要我有一台新机器,它就会在普通的powershell目录中生成standard Profile.ps1。

我的所有脚本主要都在闪存驱动器上(有些备份在家里/工作的计算机上)。在闪存驱动器上,我有我的配置文件脚本,它创建了我所有的自定义转换函数、驱动器等

我想在每次运行PowerShell时从闪存中加载配置文件脚本。
因此,在我使用的所有计算机上,我的
$profile
中的代码如下所示:

#drive name of my flash; obviously different on each computer
$global:psflash = "g:\"

# if my flash disk is available, load my profile script from the flash disk
if (test-path $psflash) {
  . (join-path $psflash 'dev\powershell\PsProfile.ps1')
}
好的副作用是,我的所有脚本都可以使用全局变量
$psflash
导入它们所依赖的其他脚本或其他模块,导入方式与我的配置文件中相同(使用
连接路径