{"id":72022,"date":"2015-07-21T00:01:00","date_gmt":"2015-07-21T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/07\/21\/i-have-a-powershell-profilenow-what\/"},"modified":"2019-02-18T09:46:55","modified_gmt":"2019-02-18T16:46:55","slug":"i-have-a-powershell-profilenow-what","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/i-have-a-powershell-profilenow-what\/","title":{"rendered":"I Have a PowerShell Profile&#8212;Now What?"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Ed Wilson, Microsoft Scripting Guy, talks about the what to add into a Windows PowerShell profile.<\/span>\nMicrosoft Scripting Guy, Ed Wilson, is here. It was a beautiful sunny weekend in central Florida. The Scripting Wife and I headed to Tampa, where we met up with various Windows PowerShell peeps. It is good to get together and talk about cool stuff with cool people. The Microsoft office in Tampa is a really cool place to hang out, and it has awesome views of the harbor. There are also lots of really good restaurants in town.\nAnyway, when I am around Windows PowerShell people, one of the things I tend to ask them is what they have in their profiles. The answers are usually pretty interesting. In addition to providing good ideas, their answers also lend insight into how people use Windows PowerShell and the kinds of things they do with it.\nI like to organize my Windows PowerShell profile into sections because it helps me keep track of stuff.\nAs you may know, a Windows PowerShell profile is sort of like the old-fashioned autoexec.bat file. It is simply a file that has a special name and resides in a special place. Unlike the autoexec.bat file, however, there are different files that can be in different places, and that will have different scope.\nThis can become really confusing if one does not do a little bit of planning at the outset. There are really six profiles that are available by default:<\/p>\n<ul>\n<li>All user profiles for all hosts<\/li>\n<li>All user profiles for current host<\/li>\n<li>Current user profiles for current host<\/li>\n<li>Current user profiles for all hosts<\/li>\n<\/ul>\n<p>In addition, the current host profiles exist for the Windows PowerShell console and the Windows PowerShell ISE.\nIf I type <b>$profile<\/b>, I get the current user\/current host profile location. So, if I type <b>$profile<\/b> in the Windows PowerShell console, it points to one location, and if I type <b>$profile<\/b> in the Windows PowerShell ISE, it points to another location: This is shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $host.name<\/p>\n<p style=\"margin-left:30px\">ConsoleHost<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $PROFILE<\/p>\n<p style=\"margin-left:30px\">C:\\Users\\ed\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $Host.Name<\/p>\n<p style=\"margin-left:30px\">Windows PowerShell ISE Host<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; $profile<\/p>\n<p style=\"margin-left:30px\">C:\\Users\\ed\\Documents\\WindowsPowerShell\\Microsoft.PowerShellISE_profile.ps1\nIf I want to affect something in my Windows PowerShell experience, for both the Windows PowerShell console and the Windows PowerShell ISE, I have two choices:<\/p>\n<ul>\n<li>I can copy the same code to both profiles that I listed previously.<\/li>\n<li>I can simply copy it once to the current user ALL host profile, which located here:<\/li>\n<\/ul>\n<p style=\"margin-left:60px\">PS C:\\&gt; $PROFILE.CurrentUserAllHosts<\/p>\n<p style=\"margin-left:60px\">C:\\Users\\ed\\Documents\\WindowsPowerShell\\profile.ps1\nThis is a design decision that I will talk about later. For now, let&#8217;s work with the current user\/current host profile for the Windows PowerShell console, that is <b>$profile<\/b> when it is typed in the Windows PowerShell console.\nI generally put in these four types of things in my Windows PowerShell profile:<\/p>\n<ul>\n<li>Aliases<\/li>\n<li>Functions<\/li>\n<li>PSDrives<\/li>\n<li>Commands<\/li>\n<\/ul>\n<p>In yesterday&#8217;s post, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2015\/07\/20\/all-about-powershell-profiles.aspx\" target=\"_blank\">All About PowerShell Profiles<\/a>, I added two commands:<\/p>\n<p style=\"margin-left:30px\">Set-Location C:\\\n~and<\/p>\n<p style=\"margin-left:30px\">Start-Transcript\nThese commands would go into a section of my profile that I call <b>#Commands<\/b>.\nHere is a blank Windows PowerShell profile:<\/p>\n<p style=\"margin-left:30px\">#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p style=\"margin-left:30px\">#<\/p>\n<p style=\"margin-left:30px\"># PowerShell console profile<\/p>\n<p style=\"margin-left:30px\"># ed wilson, msft<\/p>\n<p style=\"margin-left:30px\">#<\/p>\n<p style=\"margin-left:30px\"># NOTES: contains five types of things: aliases, functions, psdrives,<\/p>\n<p style=\"margin-left:30px\"># variables, and commands.<\/p>\n<p style=\"margin-left:30px\"># version 1.0<\/p>\n<p style=\"margin-left:30px\"># 7\/20\/2015<\/p>\n<p style=\"margin-left:30px\"># HSG 7-21-2015<\/p>\n<p style=\"margin-left:30px\">#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p style=\"margin-left:30px\">#Aliases<\/p>\n<p style=\"margin-left:30px\">#Functions<\/p>\n<p style=\"margin-left:30px\"># Variables<\/p>\n<p style=\"margin-left:30px\">#PS_Drives<\/p>\n<p style=\"margin-left:30px\">#Commands\nWhen I use my template for my profile, I simply add the things I want to appear in the profile.\nOne of the first things I like to do is to add a function to edit my profile. I like to use the Windows PowerShell ISE to do this, so the command is simple:<\/p>\n<p style=\"margin-left:30px\">function edit-profile {ise $profile}.\nI then like to create an alias for the function. <b>EP<\/b> seems to be a good choice for an alias for my &#8220;edit profile&#8221; function, so I use the <b>Set-Alias<\/b> cmdlet to do that.<\/p>\n<p style=\"margin-left:30px\"><b>Note&nbsp;<\/b> The PSCX module has an <b>EP <\/b>alias, and it has a function <b>Edit-Profile<\/b>. But their function uses Notepad instead of the ISE, so I like mine instead. Because my profile loads before their module, my alias and function takes preference over theirs on my system.\nI like to create a few variables, such as an easy variable that points to my <b>Documents<\/b> folder. I call it <b>Doc<\/b>, and I use the <b>New-Variable<\/b> cmdlet to create that.\nI also like a module drive for my personal modules. I pick up the path from the <b>$psmodulehome<\/b> environmental variable. I split it and take the first element. As you can see here, my personal profile is coming along in terms of functionality:<\/p>\n<p style=\"margin-left:30px\">#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p style=\"margin-left:30px\">#<\/p>\n<p style=\"margin-left:30px\"># PowerShell console profile<\/p>\n<p style=\"margin-left:30px\"># ed wilson, msft<\/p>\n<p style=\"margin-left:30px\">#<\/p>\n<p style=\"margin-left:30px\"># NOTES: contains five types of things: aliases, functions, psdrives,<\/p>\n<p style=\"margin-left:30px\"># variables and commands.<\/p>\n<p style=\"margin-left:30px\"># version 1.0<\/p>\n<p style=\"margin-left:30px\"># 7\/20\/2015<\/p>\n<p style=\"margin-left:30px\"># HSG 7-21-2015<\/p>\n<p style=\"margin-left:30px\">#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p style=\"margin-left:30px\">#Aliases<\/p>\n<p style=\"margin-left:30px\">Set-Alias -Name ep -Value edit-profile | out-null<\/p>\n<p style=\"margin-left:30px\">#Functions<\/p>\n<p style=\"margin-left:30px\">Function Edit-Profile<\/p>\n<p style=\"margin-left:30px\">{ ISE $profile }<\/p>\n<p style=\"margin-left:30px\">#Variables<\/p>\n<p style=\"margin-left:30px\">New-Variable -Name doc -Value &#8220;$home\\documents&#8221;<\/p>\n<p style=\"margin-left:30px\">#PS_Drives<\/p>\n<p style=\"margin-left:30px\">New-PSDrive -Name Mod -Root ($env:PSModulePath -split &#8216;;&#8217;)[0] `<\/p>\n<p style=\"margin-left:30px\">&nbsp;-PSProvider FileSystem | out-null<\/p>\n<p style=\"margin-left:30px\">#Commands<\/p>\n<p style=\"margin-left:30px\">Set-Location c:\\<\/p>\n<p style=\"margin-left:30px\">Start-Transcript\nNow you have an introduction to using Windows PowerShell profiles. Profile Week will continue tomorrow when I will talk about more cool stuff.\nI 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=\"http:\/\/blogs.technet.commailto: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.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b><span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about the what to add into a Windows PowerShell profile. Microsoft Scripting Guy, Ed Wilson, is here. It was a beautiful sunny weekend in central Florida. The Scripting Wife and I headed to Tampa, where we met up with various Windows PowerShell peeps. It is good to get [&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,144,3,4,45],"class_list":["post-72022","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-profiles","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about the what to add into a Windows PowerShell profile. Microsoft Scripting Guy, Ed Wilson, is here. It was a beautiful sunny weekend in central Florida. The Scripting Wife and I headed to Tampa, where we met up with various Windows PowerShell peeps. It is good to get [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/72022","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=72022"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/72022\/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=72022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=72022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=72022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}