A PowerShell profile is a PowerShell script that runs automatically when a new PowerShell session is started. PowerShell profiles can be used to configure your PowerShell environment the way you like it, or to load custom functions for use in your PowerShell administration tasks.
There are actually six PowerShell profiles relating to the PowerShell console and the PowerShell ISE. You can see the four console-related profiles by running the following command:
PS C:\> $profile | Get-Member -MemberType NoteProperty | fl name,definition Name : AllUsersAllHosts Definition : string AllUsersAllHosts=C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 Name : AllUsersCurrentHost Definition : string AllUsersCurrentHost=C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 Name : CurrentUserAllHosts Definition : string CurrentUserAllHosts=C:\Users\Paul\Documents\WindowsPowerShell\profile.ps1 Name : CurrentUserCurrentHost Definition : string CurrentUserCurrentHost=C:\Users\Paul\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
The two additional ISE-related profiles are:
- Current User, Current Host – ISE: $Home\[My]Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
- All Users, Current Host – ISE: $PsHome\Microsoft.PowerShellISE_profile.ps1
For the purposes of this article I will be referring to the Current User, Current Host profile.
You can check for an existing PowerShell profile by using Test-Path.
PS C:\> Test-Path $profile False
If there is no existing profile create one with New-Item.
PS C:\> New-Item $profile -ItemType File -Force Directory: C:\Users\Paul\Documents\Windows\PowerShell Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 29/09/2014 2:30 PM 0 Microsoft.PowerShell_profile.ps1
You can now edit the profile script using the PowerShell ISE or your PowerShell editor of choice and add custom functions and any other customizations that you require for your PowerShell console sessions.
PS C:\> powershell_ise.exe $profile
Thank you for this! Most everywhere else has the insufficient suggestion of >> $profile | Get-Member -MemberType NoteProperty << without the pipe to name,definition which turned out to be mondo helpful.
Pingback: PowerShell Function to Connect to Exchange On-Premises
Pingback: 3 PowerShell Profiles – Connect to O365 | The Network Aficionado
I find the Powershell Profile to be very helpful in Exchange. Because the use of the Exchange Shell is getting more and more prevalent, I need to keep a historical record of what I ran and when. For this, I use the start-transcript as the first line in my PowerShell Profile.
I have several other entries, but I have a question:
How can I edit/modify/create a profile on all the servers in my domain? I hate having to log onto all the servers individually and manually create a powershell profile on each server and then it’s only for me…
Is there a way to automate this at all?
Yep. Note the part of the article above that mentions the other profile types that are available.
Pingback: PowerShell Function to Connect to Office 365