Question:
I am using Microsoft PowerShell v4
:
1 2 3 4 5 6 7 8 9 10 11 12 |
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 |
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:
1 2 |
C:\Documents and Settings\User\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 |
If the Microsoft.PowerShell_profile.ps1
file does not exist just create it.