Create PowerShell Profile File
Introduction to Windows PowerShell's Profile Path
Old timers can remember configuration files such as AutoExec.bat and Config.sys to control the startup environment, and more modern Microsoft operating systems need boot.ini or bcdedit. Well, the purpose of this page is to configure the equivalent PowerShell start-up file: Microsoft.PowerShell_profile.
PowerShell User Profile Topics
When I installed my Windows PowerShell it did not configure the profile.ps1 file automatically. A little research revealed that the key folder is called 'WindowsPowerShell'. I want to spare you the grief I suffered in finding and creating my profile file.
Remember that the purpose of these Microsoft PowerShell profile files is to control the initial settings, for example, set the working directory and add PowerShell snap-Ins.
Profiles.ps1 is a script file; by default you cannot run any scripts; this is because at install the ExecutionPolicy is set to Restricted. Without making the following configuration change you may get an error message: 'The execution of scripts is disabled'. Incidentally, this is the same command that allows all PowerShell's scripts to run.
The best method is to employ PowerShell's very own commands to manipulate the registry:
Or to be more securely:
Note 1: Investigate further with: Get-Help Set-ExecutionPolicy -full.
Before we can configuring settings in profile.ps1, or Microsoft.PowerShell_profile, we must find it! Another problem could be that none of the possible profile files exist. For a solution, let us employ PowerShell's own Test-Path cmdlet:
# Check path of PowerShell profile file
Note 2: $Profile is an environmental variable.
Note 3: If the result is 'False' then we can use PowerShell itself to create the file, thus:
# Command to create a PowerShell profile
Note 4: Once more, we can use PowerShell to edit this crucial configuration file Microsoft.PowerShell_profile.
# PowerShell command to edit profile
Simple ideas for your profile file
# Welcome message
SolarWinds' Network Performance Monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Preparation: Navigate to your Windows directory called,
Note 5: Observe the above filenames: Microsoft.PowerShell_profile is for the command-line, while the GUI version has ISE in the filename.
Here is a free tool to troubleshoot network connection and latency problems. Key concept: this is a free tool from SolarWinds that analyzes network packets captured by Wireshark (also a free tool).
When you inspect the data in the Response Time Dashboard, if you hover over an application such as Teredo or TCP, then you get an orange box showing a breakdown of network and application response times, note the 'Peak value' in addition to the 'Average'.
As an alternative to using PowerShell itself to create the file, you could launch notepad and create a files called, Microsoft.PowerShell_profile, Microsoft.PowerShellISE_profile and profile.ps1. Make sure that you have the correct file extension, .ps1 and not .txt. To recap; you should now see the file and folder in the above screen shots.
Note 6: The name of this file is 'profile' - singular (Or Microsoft.PowerShell_profile, Microsoft.PowerShellISE_profile).
Edit your profile: In the file that you created called profile.ps1, add instructions to configure your command shell. I begin by adding a simple phrase to prove that it's my profile.ps1 which is active and not the default profile.ps1. "You are now.....". PowerShell also supports the $env:Username variable.
# Welcome message
Once you have succeeded in placing your profile.ps1 in the correct path, then you should see a similar command line to the screen shot to the right.
Note 7: As ever, my mission is to get you started, however, if you are interested, you can research more flashy commands to enter into this startup configuration file: profile.ps1.
Launching Snap-Ins automatically is the killer reason for mastering PowerShell Profile.ps1. A PowerShell snapin contains extra cmdlets, usually for a specialist purpose such as Quest's Active directory family of cmdlets. The trick is wire-up PowerShell Profile.ps1 to load these snap-Ins at startup.
# PowerShell Profile for PSSnapin
Note 8: For this to actually work you need to download and install the snapin. See more about PowerShell Snap-Ins.
Note 9: Another popular way of increasing the range of PowerShell commands is to import modules.
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems. Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.
Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try - it's free.
PowerShell Profile Trap
Beware, if you use profile.ps1 to heavily modify your working environment, for example with $PSDefaultParameterValues, then your scripts may not work on other machines. To see if this is occurring launch PowerShell with the -noProfile parameter, then see if your own scripts work as designed.
It is possible to configure the profile.ps1 at other locations:
As you see, one of the commands I used in profile.ps1 was cls. Actually, cls is an Alias for clear-host. Time to find out more about PowerShell's Alias?
As you are likely to spend a great deal of time at the PowerShell command line, it makes sense to spend time configuring the startup folder and appearance of shell. The first step is to locate the location(s) where the key file called Microsoft.PowerShellISE_profile is kept. Once you have found the correct folder, then you can add instructions to the profile file.
If you like this page then please share it with your friends
See more Microsoft PowerShell tutorials
If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links.