The first thing to do to understand the six Windows PowerShell profiles is to keep in mind that they move. They change (sort of like the staircases at Hogwarts). As long as you realize that they are a moving target, you will be fine. In most cases, when talking about the Windows PowerShell profile, people are referring to the current user, currenthost profile. In fact, if no one qualifies the Windows PowerShell profile with its associated scope or description, it is safe to assume that they are talking about theCurrent User, Current Host profile. Examining the $profile variableWhen you query the $profile automatic variable, it returns the path to the Current User, Current Host profile. This makes sense, and it is a great way to easily access the path to the profile. The following script illustrates this technique from within the Windows PowerShell console. PS C:\> $profile C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 Inside the Windows PowerShell ISE, when I query the $profile automatic variable, I receive the output that is shown here. PS C:\Users\ed.IAMMRED> $profile C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1 To save you a bit of analyzing… The difference between the Windows PowerShell console Current User, Current Host profile path and the Windows PowerShell ISE Current User, Current Host profile path is three letters: ISE. BB, these three letters are probably causing you problems. More than likely, you are setting something in your Windows PowerShell console profile, and it is not available inside the Windows PowerShell ISE. Unraveling the profilesYou can pipe the $profile variable to the Get-Member cmdlet and see additional properties that exist on the $profile variable. This technique is shown here. PS C:\> $PROFILE | Get-Member -MemberType noteproperty | select name
Name —- AllUsersAllHosts AllUsersCurrentHost CurrentUserAllHosts CurrentUserCurrentHost If you are accessing the $profile variable from within the Windows PowerShell console, the AllUsersCurrentHost and the CurrentUserCurrentHost note properties refer to the Windows PowerShell console. If you access the $profile variable from within the Windows PowerShell ISE, the AllUsersCurrentHost and the CurrentUserCurrentHost note properties refer to the Windows PowerShell ISE profiles. Using the $profile variable to refer to more than the current hostWhen you reference the $profile variable, by default it refers to the Current User, Current Host profile. If you pipe the variable to the Format-List cmdlet, it still refers to the Current User, Current Host profile. This technique is shown here. PS C:\> $PROFILE | Format-List * C:\Users\ed.IAMMRED\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 This leads to a bit of confusion, especially because the Get-Member cmdlet reveals the existence of multiple profiles and multiple note properties. The way to see all of the profiles for the current host, is to use the force parameter. It reveals the hidden properties. The command illustrating this technique is shown here. $PROFILE | Format-List * -Force The command and the associated output from the command are shown in the image that follows. ![]() It is possible to directly access each of these specific properties just like you would access any other property—via dotted notation. This technique is shown here. $PROFILE.CurrentUserAllHosts The path to each of the four profiles for the Windows PowerShell console are shown in the image that follows. ![]() Determine if a specific profile existsTo determine if a specific profile exists, use the Test-Path cmdlet and the appropriate flavor of the$profile variable. For example, to determine if a Current User, Current Host profile exists you can use the $profile variable with no modifier, or you can use the CurrentUserCurrentHost note property. The following example illustrates both of these. PS C:\> test-path $PROFILE True PS C:\> test-path $PROFILE.CurrentUserCurrentHost True PS C:\> In the same manner, the other three profiles that apply to the current host (in this example, I am using the Windows PowerShell console) are determined to not exist. This is shown in the code that follows. PS C:\> test-path $PROFILE.AllUsersAllHosts False PS C:\> test-path $PROFILE.AllUsersCurrentHost False PS C:\> test-path $PROFILE.CurrentUserAllHosts False PS C:\> Creating a new profileTo create a new profile for current user all hosts, use the CurrentUserAllHosts property of the $profile automatic variable, and the New-Item cmdlet. This technique is shown here. PS C:\> new-item $PROFILE.CurrentUserAllHosts -ItemType file -Force Directory: C:\Users\ed.IAMMRED\Documents\WindowsPowerShell
Mode LastWriteTime Length Name —- ————- —— —- -a— 5/17/2012 2:59 PM 0 profile.ps1 To open the profile for editing, use the ise alias as shown here. ise $PROFILE.CurrentUserAllHosts When you are finished editing the profile, save it, close the Windows PowerShell console, reopen the Windows PowerShell console, and test that your changes work properly. |