• Home
  • Topics
    • Office 365
    • Teams
    • SharePoint Online
    • Exchange 2019
    • Exchange 2016
    • Exchange 2013
    • Hybrid
    • Certificates
    • PowerShell
    • Migration
    • Security
    • Azure
  • Blog
  • Podcast
  • Webinars
  • Books
  • About
  • Videos
    • Interview Videos
    • How To Guide Videos
  • Subscribe
    • Facebook
    • Twitter
    • RSS
    • YouTube

Practical 365

You are here: Home / Exchange Server / PowerShell Tip: Create a PowerShell Profile

PowerShell Tip: Create a PowerShell Profile

September 29, 2014 by Paul Cunningham 6 Comments

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.

1
2
PS C:\> Test-Path $profile
False


If there is no existing profile create one with New-Item.

1
2
3
4
5
6
7
8
9
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.

1
PS C:\> powershell_ise.exe $profile


connect-office-365-powershell-profile-function

Examples:

  • PowerShell Function to Connect to Office 365

Exchange Server PowerShell, Scripts

Comments

  1. Meghan says

    August 20, 2019 at 7:39 am

    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.

    Reply
  2. Ed Kummel says

    October 17, 2014 at 3:34 am

    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?

    Reply
    • Paul Cunningham says

      October 17, 2014 at 9:37 am

      Yep. Note the part of the article above that mentions the other profile types that are available.

      Reply

Leave a Reply Cancel reply

You have to agree to the comment policy.

Recent Articles

  • Microsoft Launches Group Ownership Governance Policy
  • Making the Case for Identity Governance in Azure Active Directory
  • Prepare an Office 365 migration plan assessment using PowerShell
  • Microsoft Releases May 2022 Exchange Server Security Updates
  • New Future of Work for Microsoft 365, IOT and more: Practical 365 Podcast S3 Ep. 2

Copyright © 2022 Quadrotech Solutions AG · Disclosure · Privacy Policy
Alpenstrasse 15, 6304 Zug, Switzerland