Setting up your PowerShell Environment with PowerShell Profile

If you are using PowerShell frequently you might want to change some default settings to modify your PowerShell window. We can do this by creating a PowerShell Profile where you can add Alias for function you use a lot, load modules at startup, change the root directory or add path variables.

First we need to check if the Profile file already exists

#returns false if it not exists
test-path $profile

If the file does not exists, we create it with the the following command

New-Item -path $profile -type file –force

The file will be created in the Directory location. Open the file with notepad to start creating your profile.

What can we add to the profile?

Some basic stuff, like the default root location, clearing the screen when loaded or changing some colors:

set-location c:

$shell = $Host.UI.RawUI

$shell.WindowTitle= "PS"

$shell.BackgroundColor = "Black"
$shell.ForegroundColor = "White"

PATH variable

But more useful is adding folders to you PATH variable. This way you can easily use your scripts, modules or connector scripts that you might have. I keep some of those script in my dropbox folder. You can add them with the following command

$env:Path += ";C:\Users\<user>\Dropbox\SysAdminScripts\Connectors"

If I need to connect to Exchange Online for example, I can just type ConnectTo-Exchange and the connector script will run.

Aliases

Many PowerShell cmdlets have aliases, but you might want to create an alias for one of you own scripts or existing cmdlets. For example, if you use the import-module a lot, the following alias would be useful

Set-Alias im Import-Module

 

 

Leave a Comment

0 Shares
Tweet
Pin
Share
Share