Powershell v4 not importing module automatically

Question:

I am using Microsoft PowerShell v4:

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.

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

I put the rMySnapIn.dll to the path C:\PowerShell\Modules\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.

How can I get the module automatically loaded?

Answer:

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

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

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

Source:

Powershell v4 not importing module automatically by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply