Q: How can I have a certain PowerShell module always load when I start PowerShell?
You have several options for ensuring a PowerShell module always loads when PowerShell starts.
January 3, 2013
A: You have a choice of several approaches. One is to create a custom Windows PowerShell launch command that includes the import-module command or calls a script that has a number of import-module commands (in addition to other environment setup options).
For example, the PowerShell launch below imports the Hyper-V module:
%windir%system32WindowsPowerShellv1.0powershell.exe -noexit -command import-module HyperV
The easiest way to create this shortcut is to copy the existing PowerShell launch shortcut, then edit the target command to include the import.
Another option if you always want certain modules loaded and configurations loaded is to change your PowerShell profile. Information on profiles can be found at the MSDN page "Windows PowerShell Profiles." Essentially, you pick one of the four profile scripts that matches whether the configuration should apply to just your user or all users and if it's any PowerShell shell or just the Microsoft one.
For example, if I want a certain configuration for all users and all PowerShell shells, I would create file C:WindowsSystem32WindowsPowerShellv1.0profile.ps1 (there is actually an example in the examples sub-folder but it's empty). This file would then include all the normal PowerShell commands necessary to perform whatever configuration you want.
To learn more about PowerShell, you might also be interested in the PowerShell 101 series by Robert Sheldon.
About the Author
You May Also Like