Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Monday, September 24, 2012

Creating a PowerShell Profile

PowerShell has (or may have) a special script that allows you to set up your PowerShell environment when it starts.  This script can run any valid PowerShell cmdlet. This means you can load up your own functions and aliases.  I  want to caution you that if you intend to make scripts that will be used by others, make sure that you do not rely on any functionality in your profile.  If you do, your script will fail when the other user runs it.

Your profile may, or may not be there.  If you have not configured it, it may not even be there yet.  To determine if your profile is present, use this PowerShell command.

Test-Path $Profile

If it comes back True, then you already have a profile.  If not, we first need to create one.  Type this in PowerShell to create your profile.

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

    Directory: C:\Users\Jason\Documents\WindowsPowerShell


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         8/12/2012   6:40 PM          0 Microsoft.PowerShell_profile.ps1

OK, we have a profile. To edit it, just open it in the ISE from the shell.

PowerShell_ISE $Profile

Now just add what you want PowerShell to do each time you start it up.

No comments: