我对PowerShell非常陌生,有一段时间没有pipe理Windows。 我已经下载了Windows Update PowerShell模块zip( http://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc )并将其放在C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WindowsUpdate 。 PowerShell没有find这些模块。
我不想将它们存储在我的用户目录中。 我希望它们与所有其他库存PS模块位于相同的目录中。
你的问题表明你解压到:
C:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell \ V1.0 \模块\ WindowsUpdate的
这不是正确的目录。 该模块被命名为PSWindowsUpdate ,因此应该位于名为PSWindowsUpdate的目录中。 我解压缩到:
C:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell \ V1.0 \模块\ PSWindowsUpdate
以下导入模块并按预期工作:
Import-Module PSWindowsUpdate
就像我在你原来的问题的评论中发布的video一样,你不应该把你的模块放在微软放置模块的地方。 (即, C:\Windows\System32\WindowsPowershell\v1.0\Modules )
那么你应该把你的自定义PowerShell模块? 答案很简单。 将模块放在PSModulesPath环境variables(不是 System32\WindowsPowershell\v1.0\Modules指定的其中一个目录中。
PS C:\Users\ryan> $Env:PSModulePath -split ';' C:\Users\ryan\Documents\WindowsPowerShell\Modules C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\
现在我知道你只能在那里看到一个用户特定的目录。 但是你可以添加你想要的任何path到这个环境variables。 而且你可以在整个机器上做,这样会影响到所有的用户。 您可以通过转到高级系统属性在GUI中执行此操作,也可以使用setx在命令行上执行此setx 。 set命令只适用于当前会话, setx会设置一个持久的,系统范围的variables。
您也可以尝试放入PS模块
C:\Users\All Users\Documents\WindowsPowershell\Modules
但是我还没有testing过,所以你可能还需要为这个目录添加一个环境variables。
编辑:最后,不要忘记创build一个子目录你的模块,所以如果你的模块被命名为Foo,你需要创build一个PSModulePaths下的子目录Foo。
享受您的Powershell学习之旅! 🙂