5.2. Profiles

Once the console and the core PowerShell snapins have been loaded, the profile files are processed. A profile is a PowerShell script that runs automatically when Windows PowerShell starts up. It can contain commands to add aliases, define functions, and configure the console in other ways. I show you a sample profile file later in this section.

The options for profile file locations are listed here. The profile files, if present, are run in the following order:

  • %windir%\system32\WindowsPowerShell\v1.0\profile.ps1 — Sets the profile for any PowerShell console for all users

  • %windir%\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 — Sets a profile for all users but only if they are loading the default Windows PowerShell console

  • %UserProfile%\MyDocuments\WindowsPowerShell\profile.ps1 — Sets a user-specific profile for any PowerShell console that a specific user is loading

  • %UserProfile%\MyDocuments\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 — Sets a user-specific profile for a PowerShell console but only for the default Windows PowerShell console

If there is more than one profile file on a specific machine and there is any conflict between the commands in those files, the commands in the more specific profile file take precedence.

An administrator can set up profiles that are run for all users. To do that for the default Windows PowerShell console the profile file, Microsoft.PowerShell_profile.ps1, is created in the folder %windir%\System32\WindowsPowerShell\v1.0 ...

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.