GSX Blog

Enhance your PowerShell experience by automatically loading scripts

Posted by Olivier Raynaut on Wed, Dec 19, 2012

PowerShellEver wanted to customize your PowerShell terminal so you can have all your custom function or scripts loaded automatically? Although it is possible to create aliases, functions or variables, everything is only kept for the current PowerShell session, meaning that those changes will be lost after you close the shell.

In order to store the information PowerShell, you can use a “Profile” that is loaded at every session. We’ll now explain how to enable your PowerShell profile and customize it.

The different Profiles

You can have four different profiles in Windows PowerShell, listed below in load order, the most specific having precedence over less specific profiles where they apply:

  • %windir%\system32\WindowsPowerShell\v1.0\profile.ps1
    This profile applies to all users and all shells. 

  • %windir%\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
    This profile applies to all users, but only to the Microsoft.PowerShell shell. 

  • %UserProfile%\My Documents\WindowsPowerShell\profile.ps1
    This profile applies only to the current user, but affects all shells.  

  • %UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
    This profile applies only to the current user and the Microsoft.PowerShell shell.

Enabling a profile

Open a PowerShell terminal and type in


This should display the path that would be used to store you profile. However it might not be created yet, so in order to find out, type the following:

test-path $profile

If the result is true, you’re all set, else type the following to create the profile:

new-item -path $profile -itemtype file -force

You’re now all set with your profile, and can customize it, by launching the PowerShell ISE:

powershell_ise $profile


Auto-load scripts on PowerShell startup

In the ps1 file of your profile, usually named “Microsoft.PowerShell_profile.ps1”, you can enter the following code, so that the folder of your choice will contain scripts that will be executed on startup:

# directory where my scripts are stored


# load all 'autoload' scripts

Get-ChildItem "${psdir}\*.ps1" | %{.$_

Write-Host "Custom PowerShell Environment Loaded" 

This script will browse the folder given in input, and load all the files. The files I have in this folder are “.ps1” files that contains a PowerShell function.


In order for those scripts to be executed, the policy needs to be updated to something else than "restricted", at least “remotesigned” by running the following:

Set-ExecutionPolicy remoteSigned


Here you go, you can now put as many “.ps1” files as you need in your “autoload” folder, and these will be executed everytime you launch your PowerShell session.


GSX provides out-of-the box monitoring to ensure your Unified Communications applications are performing the way they should, whether they're on-premise, hybrid, or in the cloud. Find out more >>

If you haven't tried GSX' solutions yet, why not sign up for a free 14-day trial or request a personal demo.

Tags: cmdlets, Powershell, Best practices