Skip to main content
 首页 » 编程设计

powershell之如何更改 Powershell 模块的安装位置

2024年12月31日19wuhuacong

我使用的是 3.0 版,似乎没有办法指定安装所有模块的默认文件夹。特别是,我正在尝试安装 Posh-Git,但它坚持将模块安装在 MyDocuments\WindowsPowershell 中。我该如何改变?

请您参考如下方法:

默认情况下,PowerShell 在两个位置之一中查找模块,这两个位置都在
PSModulePath 环境变量。

   System modules: %windir%\System32\WindowsPowerShell\v1.0\Modules 
   Current user modules:  %UserProfile%\Documents\WindowsPowerShell\Modules 

您可以将自己的模块目录添加到路径中:
$env:PSModulePath+=';c:\MyModules'