{"id":1305,"date":"2014-05-23T00:01:00","date_gmt":"2014-05-23T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/05\/23\/whats-in-your-powershell-profile-microsoft-pfes-favorites\/"},"modified":"2014-05-23T00:01:00","modified_gmt":"2014-05-23T00:01:00","slug":"whats-in-your-powershell-profile-microsoft-pfes-favorites","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/whats-in-your-powershell-profile-microsoft-pfes-favorites\/","title":{"rendered":"What&#8217;s in Your PowerShell Profile? Microsoft PFEs&#039; Favorites"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft premier field engineers share some of their favorite functions from their Windows PowerShell profiles.\nMicrosoft Scripting Guy, Ed Wilson, is here. Today we will look at some profile excerpts from a few Microsoft premier field engineers (PFEs).\n<span style=\"font-size:large\"><b>Michael Wiley<\/b><\/span> offers the following idea:\n&#8220;I actually got this from Ashley McGlone, but I use it extensively for giving presentations and demos. My $Profile for ISE contains the following lines to make error text more readable on projectors and to increase the font size.&#8221;<\/p>\n<p style=\"margin-left:30px\"># Make error text easier to read in the console pane.<\/p>\n<p style=\"margin-left:30px\">$psISE.Options.ErrorBackgroundColor = &#8220;red&#8221;<\/p>\n<p style=\"margin-left:30px\">$psISE.Options.ErrorForegroundColor = &#8220;white&#8221;\n&nbsp;<\/p>\n<p style=\"margin-left:30px\"># Make text easier to read at larger resolutions<\/p>\n<p style=\"margin-left:30px\">$psISE.Options.Zoom = 125\n&#8220;And I use the following for the $Profile in console.&#8221;<\/p>\n<p style=\"margin-left:30px\">$a = (Get-Host).PrivateData<\/p>\n<p style=\"margin-left:30px\">$a.ErrorBackgroundColor = &#8220;red&#8221;<\/p>\n<p style=\"margin-left:30px\">$a.ErrorForegroundColor = &#8220;white&#8221;\n&#8220;I adjust the font setting on my console to 18pt Lucinda Console, and the Layout is 80 wide by 35 high.&nbsp;I also apply these same settings inside all of my virtual machines.&nbsp;On a typical 1024&#215;768 projector, this makes the text very readable for students.&#8221;\n<span style=\"font-size:large\"><b>Ashley McGlone<\/b> <\/span>(@GoateePFE) provided this additional tip:\n&#8220;As part of my work, I teach many Windows PowerShell workshops for our customers. I&rsquo;ve been using Windows PowerShell for four years, and I run a fairly minimal profile for both the console and the ISE. I do this for two reasons:\n1. I am a purist, and I like things clean and simple.\n2. I want to have a default environment when I am teaching students.\n&#8220;Here is what I use in my console profile.&#8221;<\/p>\n<p style=\"margin-left:30px\"># Clean out small files from my transcript folder<\/p>\n<p style=\"margin-left:30px\">dir C:UsersasmcglonDocumentsPowerShell_Transcripts*.txt | ? length -lt 1kb | remove-item<\/p>\n<p style=\"margin-left:30px\"># Log a transcript for every console session in case I need to go back and find a command later<\/p>\n<p style=\"margin-left:30px\">Start-Transcript -Path &#8220;C:UsersashleyDocumentsPowerShell_Transcripts$(Get-Date -Format yyyyMMddHHmmss).txt&#8221; | Out-Null<\/p>\n<p style=\"margin-left:30px\"># Set the console error colors to white text on red background.<\/p>\n<p style=\"margin-left:30px\"># This is much easier to read on a projector.<\/p>\n<p style=\"margin-left:30px\">$a = (Get-Host).PrivateData<\/p>\n<p style=\"margin-left:30px\">$a.ErrorBackgroundColor = &#8220;red&#8221;<\/p>\n<p style=\"margin-left:30px\">$a.ErrorForegroundColor = &#8220;white&#8221;\n&#8220;Here is what I use in my ISE profile.&#8221;<\/p>\n<p style=\"margin-left:30px\"># Make error text easier to read in the console pane.<\/p>\n<p style=\"margin-left:30px\">$psISE.Options.ErrorBackgroundColor = &#8220;red&#8221;<\/p>\n<p style=\"margin-left:30px\">$psISE.Options.ErrorForegroundColor = &#8220;white&#8221;<\/p>\n<p style=\"margin-left:30px\"># Make text easier to read at larger resolutions<\/p>\n<p style=\"margin-left:30px\">$psISE.Options.Zoom = 125\n&#8220;That&rsquo;s it. These very basic settings help me as I teach Windows PowerShell.&#8221;\n<span style=\"font-size:large\"><b>Funtrol Ready <\/b><\/span>says his main areas of focus are SharePoint and Windows PowerShell.\n&#8220;I use a really basic profile that connects me to Office&nbsp;365 where I can manage, demo, or troubleshoot the suite of products by using Windows PowerShell.\n&#8220;In my ISE profile, first I capture my credentials and then connect to Office&nbsp;365. This requires the installation of the Microsoft Online Services Sign-in Assistant and the Windows Azure Active Directory Module for Windows PowerShell. If I am using Windows PowerShell&nbsp;2.0, I must import the module. Windows PowerShell&nbsp;3.0 or later will automatically load them for me.&#8221;<\/p>\n<p style=\"margin-left:30px\">$o365cred = get-credential -UserName admin@&lt;my-tenant&gt;.onmicrosoft.com -Message cloudO365demo<\/p>\n<p style=\"margin-left:30px\">Connect-MsolService -Credential $o365cred\n&#8220;Next I connect to SharePoint Online. This requires downloading the SharePoint Online Management Shell.&#8221;<\/p>\n<p style=\"margin-left:30px\">connect-sposervice -url https:\/\/&lt;my-tenant&gt;-admin.sharepoint.com -Credential $o365cred\n&nbsp;&#8220;Next I connect to Lync Online. This requires the installation of the Lync Online Connector Module.&#8221;<\/p>\n<p style=\"margin-left:30px\">Import-Module LyncOnlineConnector<\/p>\n<p style=\"margin-left:30px\">$session = New-CsOnlineSession -Credential $o365cred<\/p>\n<p style=\"margin-left:30px\">Import-PSSession $session\n&#8220;And finally, I connect to Exchange Online by using a remote session.&#8221;<\/p>\n<p style=\"margin-left:30px\">$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https:\/\/ps.outlook.com\/powershell -Credential $o365cred -Authentication &#8220;Basic&#8221; -AllowRedirection<\/p>\n<p style=\"margin-left:30px\">Import-PSSession $exchangeSession\n<b><span style=\"font-size:large\">Georges Maheu<\/span> <\/b>says that he uses Windows PowerShell every day. Most of the time, he uses Windows PowerShell with scripts, but he uses the console to test things and to do research. Here are some of the functions from his profile.\n&#8220;My first function loads my profile to facilitate editions. This is very useful when you are creating your profile. The second function pipes Help text to <b>More<\/b>, which reduces scrolling. The third function lists WMI classes (excluding CIM classes). The last function is my favorite, it overwrites the default <b>Prompt<\/b> function. This provides the following:\n1. Displays a timestamp to gauge timespans between commands. I use <b>Measure-Command<\/b> for more precise timing, but this provides me with a rough order of magnitude.\n2. Displays the current path on its own line, which provides more real estate to type commands.\n3. The green color and &lsquo;&#8212;&lsquo; line provides a visual clue that separates commands.&#8221;<\/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;&#8211;<\/p>\n<p style=\"margin-left:30px\">function profile &nbsp;<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">notepad $profile<\/p>\n<p style=\"margin-left:30px\">} #function profile\n&nbsp;<\/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;&#8211;<\/p>\n<p style=\"margin-left:30px\">function moreHelp($what)<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">get-help <i>-name<\/i> $what <i>-full<\/i> | more<\/p>\n<p style=\"margin-left:30px\">} #function moreHelp\n&nbsp;<\/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;&#8211;<\/p>\n<p style=\"margin-left:30px\">function getWMI($what)<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">get-wmiobject <i>-list<\/i> |<\/p>\n<p style=\"margin-left:30px\">&nbsp; where-object {$_.name -match $what -and<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $_.name -notmatch &#8220;CIM_&#8221;}<\/p>\n<p style=\"margin-left:30px\">} #function getWMI\n&nbsp;<\/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;&#8211;<\/p>\n<p style=\"margin-left:30px\">function prompt()<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">Write-Host <i>-ForegroundColor<\/i> Green @&#8221;<\/p>\n<p style=\"margin-left:30px\">PS $(get-date) $(Get-Location)<\/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;&#8211;<\/p>\n<p style=\"margin-left:30px\">&#8220;@\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">$(if ($nestedpromptlevel -ge 1) { &#8216;&gt;&gt;&#8217; }) + &#8216;&gt; &#8216;<\/p>\n<p style=\"margin-left:30px\">} #function prompt()\n&nbsp;<\/p>\n<p style=\"margin-left:30px\"># Initialise PowerShell =======================================<\/p>\n<p style=\"margin-left:30px\"><b>&nbsp;<\/b><\/p>\n<p style=\"margin-left:30px\">(get-host).UI.RawUI.windowTitle = &#8220;George&#8217;s PowerShell&#8221;\n<b><span style=\"font-size:large\">Ian Farr<\/span> <\/b>claims to be a PowerShell addict&hellip;\n&#8220;There, I&rsquo;ve said it! I also teach Windows PowerShell and help my customers with their scripts. I&rsquo;ve got a lot in my $profile. Here&rsquo;s some of the publishable stuff.\n&#8220;I check to see whether the console has been started with &lsquo;Run as Administrator.&rsquo; If it has, I give it a different color than that of my standard console, so I instantly know what context I&rsquo;m in. I also kick off a background update of my Help files because this can only be achieved with admin permissions.&#8221;<\/p>\n<p style=\"margin-left:30px\">#Check for admin privs<\/p>\n<p style=\"margin-left:30px\">If (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;[Security.Principal.WindowsBuiltInRole] &#8220;Administrator&#8221;))<\/p>\n<p style=\"margin-left:30px\">{\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp; #Change the console display<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI = (Get-Host).UI.RawUI<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI.BackgroundColor = &#8220;blue&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI.ForegroundColor = &#8220;white&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI.WindowTitle = &#8220;Ian&#8217;s Admin PowerShell&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; Set-Location c:<\/p>\n<p style=\"margin-left:30px\">&nbsp; cls\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp; #Update Help files<\/p>\n<p style=\"margin-left:30px\">&nbsp; Start-Job -ScriptBlock {Update-Help -Force}<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p style=\"margin-left:30px\">Else<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp; #Change the console display<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI = (Get-Host).UI.RawUI<\/p>\n<p style=\"margin-left:30px\">&nbsp; $Size = $UI.WindowSize<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $Size.Width = 120<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $Size.Height = 60<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI.WindowSize = $Size<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI.BackgroundColor = &#8220;black&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI.ForegroundColor = &#8220;darkgreen&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; $UI.WindowTitle = &#8220;Ian&#8217;s PowerShell&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; cls<\/p>\n<p style=\"margin-left:30px\">}\n&#8220;The following function automatically adds &#8211;<b>AutoSize<\/b> for when I use <b>Format-Wide<\/b> or <b>Format-Table<\/b>. (I should add more of these $PsDefaultParameterValues statements because they&rsquo;re awesome!)&#8221;<\/p>\n<p style=\"margin-left:30px\">#Set Autosize switch for both Format-Table and Format-Wide cmdlet<\/p>\n<p style=\"margin-left:30px\">$PSDefaultParameterValues[&#8216;Format-[wt]*:Autosize&#8217;] = $True\n<span style=\"font-size:large\"><b>Rene Mau <\/b><\/span>likes to use Notepad and the console to write scripts.\n&#8220;When I need information about a class or object, I&rsquo;m reading the MSDN library. So the most useful profile function for me is the following. I add a <b>ScriptMethod QuerymsdnClassInfo()<\/b> to every object in the session. This method will open the MSDN website for extended information for the class.&#8221;<\/p>\n<p style=\"margin-left:30px\">#Microsoft.PowerShell_profile.ps1<br \/> $ProfilePath = Split-Path -Path $PROFILE &ndash;Parent<br \/> $TypesFile = Join-Path -Path $ProfilePath -ChildPath MyTypes.ps1xml<\/p>\n<p style=\"margin-left:30px\">try<br \/> {<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Update-TypeData -Path $TypesFile -EA Stop<br \/> }<br \/> catch [System.Management.Automation.ItemNotFoundException]<br \/> {<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Host &#8220;Update TypeData failed. Could not find $TypesFile&#8221; -ForegroundColor DarkRed<br \/> }<br \/> catch<br \/> {<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Host &#8220;Update TypeData failed. Please check syntax of $TypesFile&#8221; -ForegroundColor DarkRed<br \/> }\n<\/p>\n<p style=\"margin-left:30px\">#MyTypes.ps1xml<\/p>\n<p style=\"margin-left:30px\">&lt;Types&gt;<br \/> &nbsp;&lt;Type&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;Name&gt;System.Object&lt;\/Name&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;Members&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&lt;ScriptMethod&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;Name&gt;queryMSDNClassInfo&lt;\/Name&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;Script&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;$type = $this.GetType().FullName<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;switch -Wildcard ($type)<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &#8220;System.Management.ManagementObject&#8221; { $urilist = &#8220;http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa394554`(v=vs.85`).aspx&#8221; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &#8220;System.__ComObject&#8221; { $urilist = &#8220;http:\/\/www.microsoft.com\/com\/default.mspx&#8221; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; default { $urilist = &#8220;http:\/\/msdn.microsoft.com\/$PSUICulture\/library\/$type.aspx&#8221; }<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;}<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;foreach ($uri in $urilist)<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; If (-not $($global:iemsdn.Type) -eq &#8220;HTML Document&#8221;)<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;$global:iemsdn = new-object -comobject InternetExplorer.Application -property @{navigate2 = $uri; visible = $true}<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; else<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;$global:iemsdn.navigate2($uri,0x1000)<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;}<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;\/Script&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&lt;\/ScriptMethod&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;\/Members&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;\/Type&gt;<\/p>\n<p style=\"margin-left:30px\">&lt;\/Types&gt;\n<b><span style=\"font-size:large\">Stefan Stranger<\/span> <\/b>specializes in System Center Operations Manager and Windows PowerShell.\n&#8220;I love to use Windows PowerShell to automate and inspect systems I am working on. During the many Windows PowerShell workshops that I deliver, I&rsquo;ve added more in my profile. That&rsquo;s why I&rsquo;ve added information about what is in my profile when I start my different Windows PowerShell hosts. In my console profile, I have the following functions.&#8221;<\/p>\n<p style=\"margin-left:30px\">Write-Host &#8220;Loaded in profile: Measure-Script, Scripts drive&#8221; -ForegroundColor Yellow<\/p>\n<p style=\"margin-left:30px\">Write-Host &#8220;Loaded in profile: PSReadLine&#8221; -ForegroundColor Yellow<\/p>\n<p style=\"margin-left:30px\">Write-Host &#8220;PSReadline example: Get-Process &ndash;&lt;Ctrl+Space&gt; or Get-Process i &lt;Ctrl+Space&gt;&#8221; -ForegroundColor Yellow<\/p>\n<p style=\"margin-left:30px\"># Load Module PSProfile Module<\/p>\n<p style=\"margin-left:30px\"># More info http:\/\/www.powershellmagazine.com\/2013\/05\/13\/measuring-powershell-scripts\/<\/p>\n<p style=\"margin-left:30px\">import-module PSProfiler\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">#Go to default Script folder<\/p>\n<p style=\"margin-left:30px\">Set-Location C:ScriptsPS\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">#Create FileSystem Drive for Script folder<\/p>\n<p style=\"margin-left:30px\">New-PSDrive -Name Scripts -PSProvider FileSystem -Root C:ScriptsPS | Out-Null\n&nbsp;<\/p>\n<p style=\"margin-left:30px\"># Load Module PSReadLine Module<\/p>\n<p style=\"margin-left:30px\"># More info https:\/\/github.com\/lzybkr\/PSReadLine<\/p>\n<p style=\"margin-left:30px\">import-module PSReadLine\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">&#8220;In my ISE profile, I have the following functions.&#8221;<\/p>\n<p style=\"margin-left:30px\">Write-Host &#8220;Loaded in profile: Measure-Script, Scripts drive&#8221; -ForegroundColor Yellow<\/p>\n<p style=\"margin-left:30px\"># Load Module PSProfile Module<\/p>\n<p style=\"margin-left:30px\"># More info http:\/\/www.powershellmagazine.com\/2013\/05\/13\/measuring-powershell-scripts\/<\/p>\n<p style=\"margin-left:30px\">import-module PSProfiler\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">#Go to default Script folder<\/p>\n<p style=\"margin-left:30px\">Set-Location C:ScriptsPS\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">#Set WindowsTitle<\/p>\n<p style=\"margin-left:30px\">((Get-Host).UI.RawUI).WindowTitle = &#8220;PowerShell Rocks!&#8221;\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">#Create FileSystem Drive for Script folder<\/p>\n<p style=\"margin-left:30px\">New-PSDrive -Name Scripts -PSProvider FileSystem -Root C:ScriptsPS | Out-Null\n<\/p>\n<p style=\"margin-left:30px\">#Script Browser Begin<\/p>\n<p style=\"margin-left:30px\">Function Start-ScriptBrowser<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp; Add-Type -Path &#8216;C:Program Files (x86)Microsoft CorporationMicrosoft Script BrowserSystem.Windows.Interactivity.dll&#8217;<\/p>\n<p style=\"margin-left:30px\">&nbsp; Add-Type -Path &#8216;C:Program Files (x86)Microsoft CorporationMicrosoft Script BrowserScriptBrowser.dll&#8217;<\/p>\n<p style=\"margin-left:30px\">&nbsp; Add-Type -Path &#8216;C:Program Files (x86)Microsoft CorporationMicrosoft Script BrowserBestPractices.dll&#8217;<\/p>\n<p style=\"margin-left:30px\">&nbsp; #Check if ScriptBrowser is already added to AddOnTools<\/p>\n<p style=\"margin-left:30px\">&nbsp; if (!($psISE.CurrentPowerShellTab.VerticalAddOnTools.Name -eq &#8220;Script Browser&#8221;))<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $scriptBrowser = $psISE.CurrentPowerShellTab.VerticalAddOnTools.Add(&#8216;Script Browser&#8217;, [ScriptExplorer.Views.MainView], $true)<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp; #Check if ScriptAnalyzer is already added to AddOnTools<\/p>\n<p style=\"margin-left:30px\">&nbsp; if (!($psISE.CurrentPowerShellTab.VerticalAddOnTools.Name -eq &#8220;Script Analyzer&#8221;))<\/p>\n<p style=\"margin-left:30px\">&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $scriptAnalyzer = $psISE.CurrentPowerShellTab.VerticalAddOnTools.Add(&#8216;Script Analyzer&#8217;, [BestPractices.Views.BestPracticesView], $true)<\/p>\n<p style=\"margin-left:30px\">&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp; if (!($psISE.CurrentPowerShellTab.VerticalAddOnTools.Name -eq &#8220;Script Browser&#8221;))<\/p>\n<p style=\"margin-left:30px\">&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $psISE.CurrentPowerShellTab.VisibleVerticalAddOnTools.SelectedAddOnTool = $scriptBrowser<\/p>\n<p style=\"margin-left:30px\">&nbsp; }\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p style=\"margin-left:30px\">#Script Browser End\n&#8220;That&rsquo;s it. I write a blog on TechNet: <a href=\"http:\/\/blogs.technet.com\/b\/stefan_stranger\/\" target=\"_blank\">Stefan Stranger&#8217;s Weblog &#8211; Manage your IT Infrastructure<\/a>. You can also find me on <a href=\"https:\/\/twitter.com\/#!\/sstranger\" target=\"_blank\">Twitter<\/a>.&#8221;\n<b><span style=\"font-size:large\">Jason Walker<\/span> <\/b>offers the following ideas:\n&#8220;I like to use my Windows PowerShell profile to start off my day with a laugh. I do this with the Sapi.SPVoice COM object. When Windows PowerShell is launched, my computer is inspired by LMFAO&rsquo;s &ldquo;Party Rock Anthem,&rdquo; and it informs me that it&rsquo;s time to shuffle.\n&#8220;In the following script, first I create the Sapi.SPVoice COM object. Then I switch the voice from David to Zira, and I use <b>Get-Date<\/b> to get the day of the week to use in the greeting. Lastly, I switch the voice back to David and state the second half of the greeting.&#8221;<\/p>\n<p style=\"margin-left:30px\">#Create Sapi.Spvoice COM object<\/p>\n<p style=\"margin-left:30px\">$Sapi = New-Object -ComObject sapi.spvoice<\/p>\n<p style=\"margin-left:30px\">#Switch Voice from David to Zira<\/p>\n<p style=\"margin-left:30px\">$Sapi.Voice = $Sapi.GetVoices().Item(2)<\/p>\n<p style=\"margin-left:30px\">#State what &#8220;day of the week&#8221; shuffle it is<\/p>\n<p style=\"margin-left:30px\">$Sapi.Speak(&#8220;Time for the $((Get-Date).DayofWeek) shuffle&#8221;)<\/p>\n<p style=\"margin-left:30px\">#Switch the voice back to David<\/p>\n<p style=\"margin-left:30px\">$Sapi.Voice = $Sapi.GetVoices().Item(0)<\/p>\n<p style=\"margin-left:30px\">#Slow the rate of speach down<\/p>\n<p style=\"margin-left:30px\">$Sapi.Rate = -3<\/p>\n<p style=\"margin-left:30px\">#State last half of greeting<\/p>\n<p style=\"margin-left:30px\">$Sapi.Speak(&#8220;Everyday I&#8217;m shuff-a-linn&#8221;)\n&#8220;Yes I know&hellip;it&#8217;s kind of cheesy, but it makes me laugh.&#8221;\n<span style=\"font-size:large\"><b>Martin Schvartzman <\/b><\/span>provides the following script to configure a transcript and to import a command&#8217;s history from previous sessions:<\/p>\n<p style=\"margin-left:30px\">#region Transcript and History management<\/p>\n<p style=\"margin-left:30px\">function Bye() {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;Stop-Transcript<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;Write-Host &#8220;Transcript stopped. Exporting History&#8230; &#8221; -ForegroundColor Yellow -NoNewline<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;Get-History -Count $global:MaximumHistoryCount | Export-Clixml -Path $global:HistoryXmlFilePath<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;Write-Host &#8220;Finished!&#8221; -ForegroundColor Green<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;Start-Sleep -Milliseconds 500<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;exit<\/p>\n<p style=\"margin-left:30px\">}\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">function Hi() {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;Start-Transcript -Path $global:Transcript -ErrorAction SilentlyContinue<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &nbsp;if (Test-Path $global:HistoryXmlFilePath) {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Import-Clixml $global:HistoryXmlFilePath | Add-History }<\/p>\n<p style=\"margin-left:30px\">}\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">$global:Transcript = &#8216;C:TempTranscript_{0:yyyyMMddHHmmss}.log&#8217; -f (Get-Date)<\/p>\n<p style=\"margin-left:30px\">$global:MaximumHistoryCount = 1500<\/p>\n<p style=\"margin-left:30px\">$global:HistoryXmlFilePath = Join-Path -Path (Split-Path -Path $PROFILE -Parent) -ChildPath PSHistory.xml<\/p>\n<p style=\"margin-left:30px\">$ExitAction = { Bye }<\/p>\n<p style=\"margin-left:30px\">[void](Register-EngineEvent &ndash;SourceIdentifier PowerShell.Exiting &ndash;Action $ExitAction)<\/p>\n<p style=\"margin-left:30px\">Hi<\/p>\n<p style=\"margin-left:30px\">#endregion\n<span style=\"font-size:large\"><b>Matt Reynolds<\/b> <\/span>doesn&rsquo;t want his scripts to have accidental dependencies.\n&#8220;I try to avoid loading things in the profile because I use too many different machines. However, I have a module full of utility functions, which I load and bundle as needed. The following function is a recent addition. It provides memory efficient sums, counts, averages, and so on. It is aggregated by property values. Think of it as a pivot table on a pipeline.&#8221;<\/p>\n<p style=\"margin-left:30px\">&lt;#<\/p>\n<p style=\"margin-left:30px\">.Synopsis<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;Measures averages, sums, counts, etc over a series of object with grouping by property values, like a pivot table<\/p>\n<p style=\"margin-left:30px\">.DESCRIPTION<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;Measures averages, sums, counts, etc over a series of object with grouping by property values, like a pivot table<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;Avoids holding all the objects in memory for scalability<\/p>\n<p style=\"margin-left:30px\">.EXAMPLE<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;## Get counts, sums, avgs, etc. for file length by extension<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;Get-ChildItem c: -Recurse | Measure-MLib__Aggregate -GroupProperty Extension -MeasureProperty Length -OutPipeHt<\/p>\n<p style=\"margin-left:30px\">.EXAMPLE<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;## Get counts, sums, avgs, etc. for multiple numerical columns in a log file while grouping by multiple text columns<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;Get-Content -Path somelogfile.txt | ConvertFrom-CSV | Measure-MLib__Aggregate -GroupProperty SourceIp,RequestType -MeasureProperty Size,ResponseTime -OutPipeHt<\/p>\n<p style=\"margin-left:30px\">.INPUTS<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;Any object(S)<\/p>\n<p style=\"margin-left:30px\">.OUTPUTS<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;Varies depending on -Passthru and other parameters<\/p>\n<p style=\"margin-left:30px\">#&gt;<\/p>\n<p style=\"margin-left:30px\">function Measure-MLib__Aggregate{<\/p>\n<p style=\"margin-left:30px\">&nbsp; [CmdletBinding()]<\/p>\n<p style=\"margin-left:30px\">&nbsp; param(<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## Input any stream of objects (e.g., psobjects, hashtables, etc.) with<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## properties that you want to count\/sum\/average<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; [Parameter(ValueFromPipeline=$true)]<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; [object[]]$InputObject,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; ## Causes the input object(s) to be output instead of the measurement object<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## Use together with $SideOutputHtVariableName or $SideOutputArrayVariableName<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## to have the measurements sent to a variable while the input objects continue down output pipeline<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [switch]$Passthru,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## See Passthru<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; [string]$SideOutputHtVariableName = $null,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## See Passthru<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [string]$SideOutputArrayVariableName = $null,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## One or more property names by which to aggregate<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; [string[]]$GroupProperty,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## One or more property names by which to measure after aggregation<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; [string[]]$MeasureProperty,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## Causes the measurement results to be output as a flattened table \/ stream<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [switch]$OutPipeFlat,<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## Causes the measurement results to be output as a hierachial hashtable<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [switch]$OutPipeHt<\/p>\n<p style=\"margin-left:30px\">&nbsp; )<\/p>\n<p style=\"margin-left:30px\">&nbsp; begin{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; $groups = @{}\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; function New-MLib__MeasurementsHashTable{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param( [string[]]$propertyNames )<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $outer = @{}<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach($propertyName in $propertyNames){<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $outer[$propertyName] = @{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PropertyName = $propertyName<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Count = 0<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sum = 0<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Avg = 0<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Max = 0<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Min = 0<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $outer<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; }\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function ConvertFrom-MLib__AggregateMeasure{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param(<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [hashtable]$AggregateMeasure<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach( $aggregateKey in $AggregateMeasure.Keys ){<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach( $propertyMeasure in $AggregateMeasure[$aggregateKey].Values ){<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&amp;n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft premier field engineers share some of their favorite functions from their Windows PowerShell profiles. Microsoft Scripting Guy, Ed Wilson, is here. Today we will look at some profile excerpts from a few Microsoft premier field engineers (PFEs). Michael Wiley offers the following idea: &#8220;I actually got this from Ashley McGlone, but I use [&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":[144,3,4,45],"class_list":["post-1305","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-profiles","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft premier field engineers share some of their favorite functions from their Windows PowerShell profiles. Microsoft Scripting Guy, Ed Wilson, is here. Today we will look at some profile excerpts from a few Microsoft premier field engineers (PFEs). Michael Wiley offers the following idea: &#8220;I actually got this from Ashley McGlone, but I use [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1305","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=1305"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1305\/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=1305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}