Powershell v4无法自动导入模块 [英] Powershell v4 not importing module automatically

查看:175
本文介绍了Powershell v4无法自动导入模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft PowerShell v4:

PS C:\> get-host

Name             : ConsoleHost
Version          : 4.0
InstanceId       : 3b4b6b8d-70ec-46dd-942a-bfecf5fb6f31
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : de-CH
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

我已经在 Visual Studio 2012 中开发了一个 C#项目,目标是 .NET Framework 4 ,其中包含一些CmdletSnapin .我可以调试它们,并且一切正常.

I have developed a C# project in Visual Studio 2012 targeting .NET Framework 4 which contains some Cmdlet and the Snapin. I can debug them and everything works just fine.

我已经创建了路径C:\PowerShell\Modules\并将其添加到PSModulePath环境变量中.

I've created the path C:\PowerShell\Modules\ and added it to the PSModulePath environment variable.

我将r MySnapIn.dll放置到路径C:\PowerShell\Modules\MySnapIn.

我希望模块会自动加载,因此我可以使用我的新cmdlet,但它们没有:模块未加载.我必须写Import-Module MySnapin才能加载它.

I would expect that the module is automatically loaded so I have my new cmdlets ready to use, but they're not: the module is not loaded. I have to write Import-Module MySnapin in order to get it loaded.

如何使模块自动加载?

推荐答案

如果要自动加载,可以将Import-Module MySnapin命令行添加到

If you want to load it automatically you can add the Import-Module MySnapin command line to your PowerShell profile.

要查找PowerShell配置文件的位置,只需在PowerShell中键入$profile,默认情况下,配置文件路径为:

To find out the location of your PowerShell profile just type $profilein a PowerShell and by default the profile path is:

C:\Documents and Settings\User\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

如果Microsoft.PowerShell_profile.ps1文件不存在,则创建它.

If the Microsoft.PowerShell_profile.ps1 file does not exist just create it.

这篇关于Powershell v4无法自动导入模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆