Where can I put Powershell modules that will be accessed by multiple users?

允我心安 提交于 2019-12-19 11:53:44

问题


I used the variable $Env:PSModulePath , It provided two paths.

> C:\Users\My User\Documents\WindowsPowerShell\Modules
> C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

Seems like My User will be accessible only for me. But my module will be used by multiple person and also when uninstalling my application [I am installing my module via msi], even if some other user uninstalls it should be removed.

Can I use "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\" for my application related module? Or is there any other better place ?


回答1:


Can i use "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\" for my application related module?

No. That place is not for you as noted in the section "Rules for Installing Modules" of the module installation guidelines.

You can decide yourself where you want to put the modules that are shared for multiple users.

Some options include:

  • Create new folder in Program Files, and add that path to PSModulePath.
  • Use a network share (though this means you need to change your execution policy to allow this), as @Rubanov said.
  • Use the All Users folder for example.



回答2:


You can also put your psm1 files on a shared drive. Then import the module with

Import-Module -Name "\\SERVERNAME\Use-MyModule.psm1"

You can find more info about adding a path to PSModulePath here.



来源:https://stackoverflow.com/questions/29816008/where-can-i-put-powershell-modules-that-will-be-accessed-by-multiple-users

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