Skip navigation

Q: How can I have a certain PowerShell module always load when I start PowerShell?

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%\system32\WindowsPowerShell\v1.0\powershell.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:\Windows\System32\WindowsPowerShell\v1.0\profile.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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish