首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell安装-模块本地vs CurrentUser

PowerShell安装-模块本地vs CurrentUser
EN

Stack Overflow用户
提问于 2020-02-16 13:40:01
回答 2查看 7.4K关注 0票数 1

能给我解释一下吗?

代码语言:javascript
复制
Import-Module PSReadLine -Scope CurrentUser

Import-Module : Cannot validate argument on parameter 'Scope'.
The argument "CurrentUser" does not belong to the set "Local,Global"
specified by the ValidateSet attribute. Supply an argument that is in the
set and then try the command again.
At line:1 char:37
+     Import-Module PSReadLine -Scope CurrentUser
+                                     ~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Import-Module], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportModuleCommand

但是这个很好(!)

代码语言:javascript
复制
Install-Module PSScriptAnalyzer -Scope CurrentUser

这很好(!)

代码语言:javascript
复制
Import-Module PSReadLine -Scope Local

Install-Module的帮助文件甚至不承认错误中提到的Local|Global的存在。-Scope <String> Specifies the installation scope of the module. The acceptable values for this parameter are AllUsers and CurrentUser.

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-16 15:59:39

这些范围大不相同(摘自官方learn.microsoft.com):

导入模块-Scope

指定,此cmdlet将模块导入其中。。 此参数的可接受值为: Global.会话中的所有命令都可用。等效于全局参数。 Local.仅在当前范围内可用。 默认情况下,当从命令提示符、脚本文件或scriptblock调用时,所有命令都导入到全局会话状态。您可以使用带有本地值的-Scope参数将模块内容导入到脚本或scriptblock范围。 从另一个模块调用时,将模块中的命令(包括嵌套模块中的命令)导入到调用方的会话状态中。指定-Scope全局或-Global表示此cmdlet将模块导入全局会话状态,使其可供会话中的所有命令使用。

安装-模块-Scope

指定模块的安装范围。这个参数的可接受值是AllUsers和CurrentUser。 AllUsers作用域在计算机的所有用户都可以访问的位置安装模块: $env:ProgramFiles\PowerShell\Modules CurrentUser将模块安装在只有计算机的当前用户才能访问的位置: $home\Documents\PowerShell\Modules 如果未定义范围,则根据PowerShellGet版本设置默认值。

  • 在PowerShellGet版本2.0.0及以上版本中,默认情况是CurrentUser,安装时不需要提升。
  • 在PowerShellGet 1.x版本中,默认情况是AllUsers,安装时需要提升。
票数 6
EN

Stack Overflow用户

发布于 2020-07-10 13:29:56

对于我和那些面临类似问题的人来说,我不得不在CurrentUser周围加上花括号"{}“。否则什么都没发生。

示例:安装模块-Name SimplySql -Scope {CurrentUser}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60249072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档