{"id":77623,"date":"2016-03-29T13:48:11","date_gmt":"2016-03-29T20:48:11","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=77623"},"modified":"2019-02-18T09:10:52","modified_gmt":"2019-02-18T16:10:52","slug":"using-the-new-powershell-ise-transcript-tool","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/using-the-new-powershell-ise-transcript-tool\/","title":{"rendered":"Using the new PowerShell ISE transcript tool"},"content":{"rendered":"<p><strong>Summary<\/strong>: Ed Wilson, Microsoft Scripting Guy, talks about using the new Windows PowerShell 5.0 ISE Transcript tool.<\/p>\n<p>&nbsp;<\/p>\n<p>One of my favorite features for Windows PowerShell has always been the transcript tool. I mean, it seems like it was made for Windows PowerShell \u2026 I guess it was. What am I talking about? Well, one of my favorite ways to spend time is plugging in various Windows PowerShell commands to see what they might do. Then I try to shorten them, make them leaner, or more powerful, or modify them to better suit my needs. Back when I used to do this on other systems, I would end up copying the command, and storing it in a notebook, or in a text file. With the Windows PowerShell transcript tool, I have not only a record of my commands, and errors they generate, but also the output that comes from the command. It is a great way to learn stuff about Windows PowerShell.<\/p>\n<p>The problem, is that the Start-Transcript tool only worked in the Windows PowerShell console, and I have been using the Windows PowerShell ISE more and more \u2026 so I did like any good Windows PowerShell person would do, and I wrote my own transcript tool for the Windows PowerShell ISE.<\/p>\n<p>But now \u2026 there is a Windows PowerShell ISE transcript tool built into Windows PowerShell ISE \u2026 beginning with Windows PowerShell 5.0 on my Windows 10 computer.<\/p>\n<h2>Start the PowerShell transcript<\/h2>\n<p>So, the first thing I do is open the Windows PowerShell ISE, and in the command pane, I type the command Start-Transcript. The command outputs the path to the transcript. This appears here:<\/p>\n<p>PS C:\\&gt; Start-Transcript<\/p>\n<p>Transcript started, output file is C:\\Users\\mredw\\Documents\\PowerShell_transcript.EDL<\/p>\n<p>T.6VtWcOHE.20160329162630.txt<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Now<\/strong> I type a command. I want one that will not take up too much space, so I select the last process in the collection of objects returned by the Get-Process cmdlet (gps is an alias for get-Process). This command appears here:<\/p>\n<p>PS C:\\&gt; gps | select -Last 1<\/p>\n<p>&nbsp;<\/p>\n<p>Handles\u00a0 NPM(K)\u00a0\u00a0\u00a0 PM(K)\u00a0\u00a0\u00a0\u00a0\u00a0 WS(K) VM(M)\u00a0\u00a0 CPU(s)\u00a0\u00a0\u00a0\u00a0 Id\u00a0 SI ProcessName<\/p>\n<p>&#8212;&#8212;-\u00a0 &#8212;&#8212;\u00a0\u00a0\u00a0 &#8212;&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212;&#8211; &#8212;&#8211;\u00a0\u00a0 &#8212;&#8212;\u00a0\u00a0\u00a0\u00a0 &#8212;\u00a0 &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p>293\u00a0\u00a0\u00a0\u00a0\u00a0 18\u00a0\u00a0\u00a0\u00a0 5416\u00a0\u00a0\u00a0\u00a0\u00a0 10536\u00a0\u00a0 116\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2808\u00a0\u00a0 0 ZeroConfigService<\/p>\n<p>&nbsp;<\/p>\n<p>Ok, now I stop the transcript. To do this, I use the Stop-Transcript cmdlet. This command once again outputs the path to the transcript file. This command and output appears here:<\/p>\n<p>PS C:\\&gt; Stop-Transcript<\/p>\n<p>Transcript stopped, output file is C:\\Users\\mredw\\Documents\\PowerShell_transcript.EDL<\/p>\n<p>T.6VtWcOHE.20160329162630.txt<\/p>\n<p>&nbsp;<\/p>\n<p>Note that the transcript file is the path to my documents folder in my profile, then the word transcript and a computer name, a bit of random number, and then the date and time. I could never remember all of tha, so I copy and paste it and try to open it in notepad. The result? An error. This appears here:<\/p>\n<p>PS C:\\&gt; notepad C:\\Users\\mredw\\Documents\\PowerShell_transcript.EDL<\/p>\n<p>T.6VtWcOHE.20160329162630.txt<\/p>\n<p>T.6VtWcOHE.20160329162630.txt : The term &#8216;T.6VtWcOHE.20160329162630.txt&#8217; is not<\/p>\n<p>recognized as the name of a cmdlet, function, script file, or operable program.<\/p>\n<p>Check the spelling of the name, or if a path was included, verify that the path is<\/p>\n<p>correct and try again.<\/p>\n<p>At line:2 char:1<\/p>\n<p>+ T.6VtWcOHE.20160329162630.txt<\/p>\n<p>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<\/p>\n<p>+ CategoryInfo\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : ObjectNotFound: (T.6VtWcOHE.20160329162630.txt:String<\/p>\n<p>) [], CommandNotFoundException<\/p>\n<p>+ FullyQualifiedErrorId : CommandNotFoundException<\/p>\n<p>&nbsp;<\/p>\n<p>The problem is the path is so long, that it actually breaks into two lines. When I attempted to paste it back, I picked up a random break and the command failed. So, now I do a copy and paste again, but this time I hit backspace to remove the random break. Yeah, it works. Here is the log file:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-3-29-16-01.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77633\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-3-29-16-01-300x241.png\" alt=\"HSG-3-29-16-01\" width=\"300\" height=\"241\" \/><\/a><\/p>\n<h2>A better way to handle this long log file path<\/h2>\n<p>A better way to handle this semi random long file name in a deep profile path, is to simply capture the returned output from the Start-Transcript command. Unfortunately, what returns is simply a string. This appears here:<\/p>\n<p>PS C:\\&gt; $a = Start-Transcript<\/p>\n<p>PS C:\\&gt; $a.GetType()<\/p>\n<p>IsPublic IsSerial Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BaseType<\/p>\n<p>&#8212;&#8212;&#8211; &#8212;&#8212;&#8211; &#8212;-\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212;&#8212;&#8211;<\/p>\n<p>True\u00a0\u00a0\u00a0\u00a0 True\u00a0\u00a0\u00a0\u00a0 String\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.Object<\/p>\n<p>&nbsp;<\/p>\n<p>PS C:\\&gt; $a<\/p>\n<p>Transcript started, output file is C:\\Users\\mredw\\Documents\\PowerShell_transcript.EDL<\/p>\n<p>T.wnH7glru.20160329163437.txt<\/p>\n<p>&nbsp;<\/p>\n<p>When I wrote my transcript function, I also wrote a function called Get-TranscriptFile that parsed this string into a path that I could directly pass to notepad to open the transcript. I still have that function, but another cool cmdlet in Windows PowerShell 5 makes that a bit obsolete. That is because Windows PowerShell 5 includes a cool cmdlet called ConvertFrom-String that will create an object from a string. Here is an example:<\/p>\n<p>PS C:\\&gt; Convertfrom-String -InputObject $a<\/p>\n<p>P1 : Transcript<\/p>\n<p>P2 : started,<\/p>\n<p>P3 : output<\/p>\n<p>P4 : file<\/p>\n<p>P5 : is<\/p>\n<p>P6 : C:\\Users\\mredw\\Documents\\PowerShell_transcript.EDLT.wnH7glru.20160329163437.txt<\/p>\n<p>&nbsp;<\/p>\n<p>The part I want is the P6 property. The command appears here:<\/p>\n<p>Notepad (Convertfrom-String -InputObject $a).p6<\/p>\n<p>Sweet! So much easier than having to write my own functions and the like. PowerShell 5 for the win!<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. Also check out my <a href=\"https:\/\/blogs.technet.microsoft.com\/msoms\/\">Microsoft Operations Management Suite Blog<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about using the new Windows PowerShell 5.0 ISE Transcript tool. &nbsp; One of my favorite features for Windows PowerShell has always been the transcript tool. I mean, it seems like it was made for Windows PowerShell \u2026 I guess it was. What am I talking about? Well, one [&hellip;]<\/p>\n","protected":false},"author":599,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568],"tags":[553,609,3,608,45],"class_list":["post-77623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","tag-ise","tag-powershell-5","tag-scripting-guy","tag-windows-10","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about using the new Windows PowerShell 5.0 ISE Transcript tool. &nbsp; One of my favorite features for Windows PowerShell has always been the transcript tool. I mean, it seems like it was made for Windows PowerShell \u2026 I guess it was. What am I talking about? Well, one [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77623","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\/599"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=77623"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77623\/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=77623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=77623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=77623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}