gpt4 book ai didi

powershell - 为所有用户持久安装 PowerShell 模块

转载 作者:行者123 更新时间:2023-12-04 00:56:16 25 4
gpt4 key购买 nike

我正在通过 Octopus Deploy 安装 PowerShell 模块到许多不同的服务器上。出于测试目的,我引用了 Microsoft 的 installing PowerShell Modules 文档的指导。 .
这很好用,但正如文档所述,我的更改仅对当前 session 可见。也就是说,如果我要执行以下操作:

$modulePath = [Environment]::GetEnvironmentVariable("PSModulePath", [EnvironmentVariableTarget]::Machine)
# More practically, this would be some logic to install only if not present
$modulePath += ";C:\CustomModules"
[Environment]::SetEnvironmentVariable("PSModulePath", $modulePath, [EnvironmentVariableTarget]::Machine)
在 tentacle 服务器上自动运行此安装程序时, future 的 PowerShell session 似乎看不到新安装的模块。
如何以与配置文件无关的方式安装 PowerShell 模块,以便启动的每个 PowerShell session 都可以看到它?

最佳答案

PowerShell 只能“查看”安装在 $env:PSModulePath 中列出的目录之一中的模块。 .否则,您必须使用完整路径导入模块。

要使所有用户都可以看到新模块,您基本上有两个选择:

  • 将模块安装到默认的系统范围模块目录(C:\Windows\system32\WindowsPowerShell\v1.0\Modules)。
  • 修改系统环境,使PSModulePath变量已经包含您的自定义模块目录(例如,通过 group policy preference )。

  • 不过,后者只会对修改后启动的 PowerShell session 生效。

    关于powershell - 为所有用户持久安装 PowerShell 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20885398/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com