有没有办法更改 PowerShell 模块安装文件夹(模块在 Install-Module 之后放置的文件夹)?
这就是为什么我想这样做:
Documents\WindowsPowerShell\Modules
,
的位置符号(公司政策),
在文件路径中(类似于 this issue 。)我试过的:
$env:PSModulePath
中。 .当您启动 PowerShell 时,它会自动添加到变量中。 最佳答案
无法更改 Install-Module
的行为因此它将模块安装在自定义路径中。
但是,您可以使用 Install-Module [...] -Scope AllUsers
为所有用户安装模块。这将在 $env:ProgramFiles\PowerShell\Modules
中安装模块, 但此操作需要 提升权限 (又名本地管理员权限)。
如果您自己下载并安装模块到自定义路径(或使用 Install-Module
的替代实现),您可以修改 $env:PSModulePath
如你所愿。
您可以使用配置文件来修补 $env:PSModulePath
每次通过将其添加到您的配置文件之一来启动 PowerShell session 时:
# Prepend custom module path.
$env:PSModulePath = ((@("C:\mymodulepath") + ($env:PSModulePath -split ";")) -join ";")
来自 Modifying the PSModulePath Installation Path
To add paths to this variable, use one of the following methods:
To add a temporary value that is available only for the current session, run the following command at the command line:
$env:PSModulePath = $env:PSModulePath + ";c:\ModulePath"
To add a persistent value that is available whenever a session is opened, add the following command to a Windows PowerShell profile:
$env:PSModulePath = $env:PSModulePath + ";c:\ModulePath"
For more information about profiles, see about_Profiles in the Microsoft TechNet library.
To add a persistent variable to the registry, create a new user environment variable called
PSModulePath
using the Environment Variables Editor in the System Properties dialog box.To add a persistent variable by using a script, use the
SetEnvironmentVariable
method on the Environment class. For example, the following script adds the"C:\Program Files\Fabrikam\Module"
path to the value of thePSModulePath
environment variable for the computer. To add the path to the userPSModulePath
environment variable, set the target to"User"
.$CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine") [Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";C:\Program Files\Fabrikam\Modules", "Machine")
关于powershell - 如何更改 PowerShell 默认模块安装文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56786702/