Introduction to PowerShell’s Profile.ps1
DOS old timers may remember AutoExec.bat and Config.sys. More modern Microsoft operating systems need boot.ini; all these files control the startup environment. Well the purpose of this page is to configure the equivalent PowerShell file: profile.ps1.
PowerShell Profile.ps1 Topics
- Mission Enabling a Basic Profile.ps1
- Enabling cmdlets (Scripts) in the Registry
- Locating the path for the Profile.ps1 file
- Profile.ps1 Plan B Location
- Summary of Profile.ps1
♣
Setting up PowerShell’s Profile.ps1
Profile.ps1 location
The key to getting started is to make sure that profile.ps1 is in the correct path.
C:\Documents and Settings\All Users\Documents\PSConfiguration\profiles.ps1
alternatively
C:\Documents and Settings\%username%\Documents\PSConfiguration\profiles.ps1
Registry Setting for Scripts e.g. Profile.ps1
HKLM\Software\Microsoft\PSConfiguration\1\ShellIds \Microsoft.Management.Automation.ps1
Change the REG_SZ ExecutionPolicy from Restricted to UNRestricted or RemoteSigned (RemoteSigned as the name suggests, means that scripts from the internet must have digital certificates, however scripts on the localhost run without restriction.) For more details of setting up profile.ps1 in the \PSConfiguration folder see here.
Customising Profile.ps1
The principle behind profile.ps1 and other cmdlets with a msh extension is to save keystrokes into a file for reuse later. Once you have absorbed the concept then you can truly customize your profile.ps1, merely look at examples for ideas and then adapt the most promising to set your PowerShell environment.
Working Directory.
My first task was to change the working directory from My Documents..\..\. to
D:\ scripts. I typed set-location d:\ scripts in the Microsoft Shell – it worked. Then I put the very same commands in profile.ps1. At first PowerShell did not executed this instruction when it launched, this was because profile.ps1 was in the wrong folder.
Aliases
If you want to create Aliases that last for more than one session, then add them to your profile.ps1. Experiment at the PowerShell command prompt with set-alias aliasname Verb-Noun pair. When your alias works perfectly save the command into profile.ps1. Example: set-alias xcopy.
PowerShell Module Directory
It is possible to create the special module folder.
Guy Recommends: A Free Trial of the Network Performance Monitor (NPM) v11.5
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.
Download a free trial of Solarwinds’ Network Performance Monitor
Summary of Profile.ps1
In PowerShell RC1, profiles.ps1 does not appear in the correct folder. After you hack the registry key called ExecutionPolicy, then you can create the msh folder in the All Users\documents. Finally, you can add instructions to the profiles.ps1 file.
If you like this page then please share it with your friends
See more Microsoft PowerShell tutorials
• PowerShell Tutorials • Methods • Cmdlets • PS Snapin • Profile.ps1 • Exchange 2007
• Command & Expression Mode • PowerShell pipeline (|) • PowerShell ‘where‘ • PowerShell ‘Sort’
• Windows PowerShell Modules • Import-Module • PowerShell Module Directory
If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links.