Installing PowerShell module persistently for all users

痞子三分冷 提交于 2019-12-02 20:57:24

PowerShell can only "see" modules installed in one of the directories listed in $env:PSModulePath. Otherwise you'll have to import the module with its full path.

To make a new module visible to all users you basically have two options:

  1. Install the module to the default system-wide module directory (C:\Windows\system32\WindowsPowerShell\v1.0\Modules).
  2. Modify the system environment so that PSModulePath variable already contains your custom module directory (e.g. via a group policy preference).

The latter will only become effective for PowerShell sessions started after the modification was made, though.

This profile applies to all users and all shells.

%windir%\system32\WindowsPowerShell\v1.0\profile.ps1

After taking the steps you spelled out in your question (which I think is the general way to go), I found two ways to get the new module source recognized by Powershell:

  • Restart the machine. (Works every time.)
  • Reset the PSModulePath in each open session.

    $env:PSModulePath=[Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
    

    I found this was necessary to run in both normal and elevated prompts to get this to work without restarting in each type of prompt. (See also the conversation @ Topic: PSModulePath.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!