Skip to main content
PowerShell

Using profiles to persist settings

By February 15, 2014September 12th, 2022No Comments

PowerShell uses the concept of “profiles” to provide login scripts to the PowerShell console. These scripts can provide access to aliases that you may commonly need, PSDrives and as we will look at here loading commonly used snap-ins. Each time the console is started the script will echo and the settings read that you have established in the script.

Expanding the variable $PROFILE will display the path to the user’s profile

C:UsersandrewDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1

This is a script and has the PS1 extension so script execution has to be allowed, either locally or though a Group Policy. To allow scripts to run locally open a PowerSell console as administrator and run the command

Set-ExecutionPolicy RemoteSigned

To edit the profile we could use the following command to open the expanded $PROFILE variable:

notepad $ExecutionContext.InvokeCommand.ExpandString($profile)

If we need regular access to the Citrix Snapins we could add this line tot he script.

add-pssnapin Citrix*

Now each time we start the console as this user we will load the Citrix snapins.