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:

<code>%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command import-module HyperV</code>

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.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottYou'll have the opportunity to experience:
• The Microsoft
Technology Roadmap
• Office 365 Implementation
• Hyper-V Optimizing
• Windows 8 Deployment
and much more!

Come See Paul Thurrott & Rod Trent in Person!

Early Registration Now Open

Upcoming Training

Mastering System Center 2012

During over 6 hours of training you can join John Savill from your computer as he will walk you through the key components and capabilities of System Center 2012, what’s involved in using the components, and the benefit they can bring to your environment.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.