Getting Started with PowerShell Profiles

This article is going to show you how easy it can be to create a PowerShell profile and start using it to make your administration go much more smoothly.

What are PowerShell Profiles?

Your PowerShell profile is not some mysterious collection of settings buried deep in the registry. You don’t need any more skill or expertise to use your PowerShell profile than you need to use anything else in PowerShell.

In simple terms, your PowerShell profile is your own personal script that runs each time you start PowerShell. Your PowerShell profile also serves as a place for you to load consistent settings, drives, and custom commands.

When you use PowerShell, there’s a variable called $profile. It references a location on the hard drive that contains your profile. Go ahead, and look at it. It’s been sitting on your computer the entire time.

The PowerShell profile variable. (Image Credit: Michael Simmons)

There are two things worth pointing out here:

PowerShell_ISE is in the filename. This is important because there are actually two profiles, one for the PowerShell console and one for PowerShell ISE.

.PS1 file extension. This is important because you should recognize that the file extension represents a PowerShell script, and that’s exacty what the profile is.

Knowing that you’ve got a script that runs each time you start PowerShell, you may already be thinking “Actually, I could really use that to do x, or y, or x AND y!” If you’re looking for some inspiration, read on as I show you three simple things that I use my profile to customize the look and operation of my PowerShell sessions.

Creating Your PowerShell Profile

You’ve already seen that PowerShell has been trying to load a profile each time a new session is launched. Even if you haven’t created your PowerShell profile, it’s not too late because the file doesn’t exist. If you want to begin using a profile, you’ll need to create a new file.

I create the profile using the New-Item cmdlet, which can be used to create files or directories. If you already have a profile, then you can take advantage of the Test-Path cmdlet and testing true or false to determine whether the profile exists.

Note that you can enter this code directly in PowerShell session to execute. Simply copy and paste it into your session.

Although the file is a little different between the PowerShell console and ISE, those changes are reflected in the value of the $Profile variable, so this code works in both the console and ISE.

Add it into each one to create your profile.

Editing Your PowerShell profile

Now that you have a profile, you can edit it just like any other PowerShell script. You can use your favorite PowerShell script editor, but I think PowerShell ISE is great choice.

Use this command to open your profile in the ISE:

PowerShell

1

ISE$profile

Three Great Uses with the PowerShell Profile

Having a profile is all well and good, but it’s not going to help you unless you have a good use for one. Here are some great uses for profiles that might get you thinking.

Set an alternate credential

You probably have two accounts, the account you log into and your administrative account. If that’s the case, then you’re likely familiar with the problem of having to constantly use administrative accounts while you’re logged into your regular everyday account.

PowerShell

1

$Global:AdminMe=Get-Credential–Username“<domain\adminaccount>”

The downside of this approach is that you will now have to login every time you start PowerShell. But I still like it because I can avoid having to sign in multiple times throughout the session because when I need to access a resource as my administrator account I just need to use the -Credential $AdminMe parameter.

Map PowerShell drives

Do you frequent certain network shares throughout the day? If you have a central file server that houses your utilities and tools, why not map to it directly from PowerShell?

MEMBER LOGIN:

BECOME A PETRI MEMBER:

About the Contributor

Michael Simmons is an IT Veteran with over 15 years of experience. He currently resides in Fairbanks, AK where he writes on technology news at www.geekSerious.com and blogs about system administration and automation at www.iLovePowerShell.com.

Michael has held a number of jobs in the IT industry, including help desk analyst, system administrator, and technology blogger. His favorite technologies are SharePoint and PowerShell, and he is a huge fan of the Microsoft platform.

He programs with .NET and C# using Visual Studio, and supports both Windows and Mac.