Installing PowerShell module persistently for all users

前端 未结 3 558
青春惊慌失措
青春惊慌失措 2021-02-03 10:22

I\'m installing a PowerShell module via Octopus Deploy onto a number of different servers. For testing purposes, I went with the guidance of Microsoft\'s documentation for insta

相关标签:
3条回答
  • 2021-02-03 10:32

    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.

    0 讨论(0)
  • 2021-02-03 10:40

    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.)

    0 讨论(0)
  • 2021-02-03 10:41

    This profile applies to all users and all shells.

    %windir%\system32\WindowsPowerShell\v1.0\profile.ps1
    
    0 讨论(0)
提交回复
热议问题