{"id":9361,"date":"2012-05-21T00:01:00","date_gmt":"2012-05-21T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/05\/21\/understanding-the-six-powershell-profiles\/"},"modified":"2012-05-21T00:01:00","modified_gmt":"2012-05-21T00:01:00","slug":"understanding-the-six-powershell-profiles","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/understanding-the-six-powershell-profiles\/","title":{"rendered":"Understanding the Six PowerShell Profiles"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, discusses the six different Windows PowerShell profiles, and when to use each.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy! Dude, I have been reading some of the posts in your most excellent blog; and first of all, I want to say I think you are great. Now for the question: I do not get the Windows PowerShell profile. I mean I get it, but not really. Here is part of my problem. I put some things in the profile, and then I go back and they are not there. Like, what is up with that? I hope you can help me. By the way, I am, like, totally looking forward to seeing you and the Scripting Wife at TechEd 2012 in Orlando. You will know me, because I sort of look like <a href=\"http:\/\/en.wikipedia.org\/wiki\/Steve_Urkel\" target=\"_blank\">Urkel<\/a>, and I always wear plaid shirts (but I don&rsquo;t wear suspenders).<\/p>\n<p>&mdash;BB<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello BB,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Last week was an absolutely great week. The Scripting Wife and I had dinner one night with Rich from the NYC Windows PowerShell Users Group (he is also a moderator for the Scripting Guys forum and writer of a couple of guest blogs). Rich was kind enough to bring me some Gunpower green tea, and I am sipping some right now. It is wonderful with a half teaspoon of organic lavender added to the pot. We also had the PowerScripting Podcast with the two winners of the 2012 Scripting Games and Jeffrey Snover. That conversation was fun and informative. I also enjoy talking to Jeffrey, and I look forward to sitting-in on at least one of his sessions at Microsoft TechEd 2012.<\/p>\n<h2>Six, count &lsquo;em, six different PowerShell profiles<\/h2>\n<p>BB, there is no doubt that you are a bit confused with Windows PowerShell profiles. There are, in fact, six different profiles. The Windows PowerShell console and the Windows PowerShell ISE have their own profiles. In addition, there are profiles for the current user and profiles for all users. The table that follows lists the six profiles and their associated locations.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"175\" valign=\"top\">\n<p><b>Description <\/b><\/p>\n<\/td>\n<td width=\"463\" valign=\"top\">\n<p><b>Path<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"175\" valign=\"top\">\n<p>Current User, Current Host &#8211; console<\/p>\n<\/td>\n<td width=\"463\" valign=\"top\">\n<p>$Home\\[My ]Documents\\WindowsPowerShell\\Profile.ps1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"175\" valign=\"top\">\n<p>Current User, All Hosts&nbsp;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"463\" valign=\"top\">\n<p>$Home\\[My ]Documents\\Profile.ps1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"175\" valign=\"top\">\n<p>All Users, Current Host &#8211; console&nbsp;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"463\" valign=\"top\">\n<p>$PsHome\\Microsoft.PowerShell_profile.ps1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"175\" valign=\"top\">\n<p>All Users, All Hosts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"463\" valign=\"top\">\n<p>$PsHome\\Profile.ps1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"175\" valign=\"top\">\n<p>Current user, Current Host &#8211; ISE<\/p>\n<\/td>\n<td width=\"463\" valign=\"top\">\n<p>$Home\\[My ]Documents\\WindowsPowerShell\\Microsoft.P owerShellISE_profile.ps1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"175\" valign=\"top\">\n<p>&nbsp;All users, Current Host &#8211; ISE&nbsp;&nbsp;<\/p>\n<\/td>\n<td width=\"463\" valign=\"top\">\n<p>$PsHome\\Microsoft.PowerShellISE_profile.ps1<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2>Understanding the six Windows PowerShell profiles<\/h2>\n<p>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 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Hogwarts\" target=\"_blank\">Hogwarts<\/a>). 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 <i>current user, current<\/i> <i>host<\/i> 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 the <i><em>C<\/em><i>urrent User, Current Host<\/i>&nbsp;<\/i>profile.<\/p>\n<p><b>Note&nbsp;&nbsp;&nbsp;<\/b>A Windows PowerShell profile (any one of the six) is simply a Windows PowerShell script. It has a special name, and it resides in a special place, but it is simply a script. In this regard, it is sort of like the old-fashioned <a href=\"http:\/\/en.wikipedia.org\/wiki\/AUTOEXEC.BAT\" target=\"_blank\">autoexec.bat<\/a> batch file. Because the Windows PowerShell profile is a Windows PowerShell script, you must enable the Script Execution policy prior to configuring and using a Windows PowerShell profile. For information about the Script Execution policy refer to <a href=\"http:\/\/blogs.technet.com\/search\/searchresults.aspx?q=%22Script%20execution%20policy%22&amp;sections=7618\" target=\"_blank\">this collection of Hey, Scripting Guy! Blogs<\/a>.<\/p>\n<h2>Examining the $profile variable<\/h2>\n<p>When you query the <b>$profile<\/b> automatic variable, it returns the path to the <em>C<\/em><i>urrent User, Current Host<\/i> 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.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $profile<\/p>\n<p style=\"padding-left: 30px\">C:\\Users\\ed.IAMMRED\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1<\/p>\n<p>Inside the Windows PowerShell ISE, when I query the <b>$profile<\/b> automatic variable, I receive the output that is shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\Users\\ed.IAMMRED&gt; $profile<\/p>\n<p style=\"padding-left: 30px\">C:\\Users\\ed.IAMMRED\\Documents\\WindowsPowerShell\\Microsoft.PowerShell<b>ISE<\/b>_profile.ps1<\/p>\n<p>To save you a bit of analyzing&hellip;<\/p>\n<p>The difference between the Windows PowerShell console <i><em>C<\/em><i>urrent User, Current Host<\/i>&nbsp;<\/i>profile path and the Windows PowerShell ISE <em>C<\/em><i>urrent User, Current Host<\/i>&nbsp;profile path is three letters: <i>ISE. <\/i><\/p>\n<p>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.<\/p>\n<h3>Unraveling the profiles<\/h3>\n<p>You can pipe the <b>$profile <\/b>variable to the <b>Get-Member<\/b> cmdlet and see additional properties that exist on the <b>$profile<\/b> variable. This technique is shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $PROFILE | Get-Member -MemberType noteproperty | select name<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name<\/p>\n<p style=\"padding-left: 30px\">&#8212;-<\/p>\n<p style=\"padding-left: 30px\">AllUsersAllHosts<\/p>\n<p style=\"padding-left: 30px\">AllUsersCurrentHost<\/p>\n<p style=\"padding-left: 30px\">CurrentUserAllHosts<\/p>\n<p style=\"padding-left: 30px\">CurrentUserCurrentHost<\/p>\n<p>If you are accessing the <b>$profile<\/b> variable from within the Windows PowerShell console, the <b>AllUsersCurrentHost<\/b> and the <b>CurrentUserCurrentHost<\/b> note properties refer to the Windows PowerShell console. If you access the <b>$profile<\/b> variable from within the Windows PowerShell ISE, the <b>AllUsersCurrentHost<\/b> and the <b>CurrentUserCurrentHost <\/b>note properties refer to the Windows PowerShell ISE profiles.<\/p>\n<h3>Using the $profile variable to refer to more than the current host<\/h3>\n<p>When you reference the <b>$profile<\/b> variable, by default it refers to the <i><em>C<\/em><i>urrent User, Current Host<\/i>&nbsp;<\/i>profile. If you pipe the variable to the <b>Format-List<\/b> cmdlet, it still refers to the <em>C<\/em><i>urrent User, Current Host<\/i>&nbsp;profile. This technique is shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $PROFILE | Format-List *<\/p>\n<p style=\"padding-left: 30px\">C:\\Users\\ed.IAMMRED\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1<\/p>\n<p>This leads to a bit of confusion, especially because the <b>Get-Member<\/b> 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 <i>force <\/i>parameter. It reveals the hidden properties. The command illustrating this technique is shown here.<\/p>\n<p style=\"padding-left: 30px\">$PROFILE | Format-List * -Force<\/p>\n<p>The command and the associated output from the command are shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4532.hsg-5-21-12-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4532.hsg-5-21-12-01.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>It is possible to directly access each of these specific properties just like you would access any other property&mdash;via dotted notation. This technique is shown here.<\/p>\n<p style=\"padding-left: 30px\">$PROFILE.CurrentUserAllHosts<\/p>\n<p>The path to each of the four profiles for the Windows PowerShell console are shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2308.hsg-5-21-12-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2308.hsg-5-21-12-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<h2>Determine if a specific profile exists<\/h2>\n<p>To determine if a specific profile exists, use the <b>Test-Path <\/b>cmdlet and the appropriate flavor<i> <\/i>of the <b>$profile<\/b> variable. For example, to determine if a <i><em>C<\/em><i>urrent User, Current Host<\/i>&nbsp;<\/i>profile exists you can use the <b>$profile<\/b> variable with no modifier, or you can use the <strong>Cu<\/strong><b>rrentUserCurrentHost<\/b> note property. The following example illustrates both of these.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; test-path $PROFILE<\/p>\n<p style=\"padding-left: 30px\">True<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; test-path $PROFILE.CurrentUserCurrentHost<\/p>\n<p style=\"padding-left: 30px\">True<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt;<\/p>\n<p>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.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; test-path $PROFILE.AllUsersAllHosts<\/p>\n<p style=\"padding-left: 30px\">False<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; test-path $PROFILE.AllUsersCurrentHost<\/p>\n<p style=\"padding-left: 30px\">False<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; test-path $PROFILE.CurrentUserAllHosts<\/p>\n<p style=\"padding-left: 30px\">False<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt;<\/p>\n<h2>Creating a new profile<\/h2>\n<p>To create a new profile for <i>current user all hosts, <\/i>use the <strong>Cu<\/strong><b>rrentUserAllHosts<\/b><i> <\/i>property of the <b>$profile<\/b> automatic variable, and the <b>New-Item<\/b> cmdlet. This technique is shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; new-item $PROFILE.CurrentUserAllHosts -ItemType file -Force<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\Users\\ed.IAMMRED\\Documents\\WindowsPowerShell<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LastWriteTime&nbsp;&nbsp;&nbsp;&nbsp; Length Name<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212; &#8212;-<\/p>\n<p style=\"padding-left: 30px\">-a&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5\/17\/2012&nbsp;&nbsp; 2:59 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 profile.ps1<\/p>\n<p>To open the profile for editing, use the<b> ise<\/b><i> <\/i>alias as shown here.<\/p>\n<p style=\"padding-left: 30px\">ise $PROFILE.CurrentUserAllHosts<\/p>\n<p>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.<\/p>\n<p>BB, that is all there is to using the <b>$profile<\/b> variable to discover different Windows PowerShell profiles. Windows PowerShell Profile Week will continue tomorrow when I will talk about editing and testing a Windows PowerShell profile.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, discusses the six different Windows PowerShell profiles, and when to use each. &nbsp;Hey, Scripting Guy! Dude, I have been reading some of the posts in your most excellent blog; and first of all, I want to say I think you are great. Now for the question: I do not [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,3,4,45],"class_list":["post-9361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, discusses the six different Windows PowerShell profiles, and when to use each. &nbsp;Hey, Scripting Guy! Dude, I have been reading some of the posts in your most excellent blog; and first of all, I want to say I think you are great. Now for the question: I do not [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/9361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=9361"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/9361\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=9361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=9361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=9361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}