{"id":17011,"date":"2010-09-25T00:01:00","date_gmt":"2010-09-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/09\/25\/create-a-transcript-of-commands-from-the-windows-powershell-ise\/"},"modified":"2010-09-25T00:01:00","modified_gmt":"2010-09-25T00:01:00","slug":"create-a-transcript-of-commands-from-the-windows-powershell-ise","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/create-a-transcript-of-commands-from-the-windows-powershell-ise\/","title":{"rendered":"Create a Transcript of Commands from the Windows PowerShell ISE"},"content":{"rendered":"<p><strong><\/strong><\/p>\n<p><strong>Summary<\/strong>: Create a transcript of commands from the Windows PowerShell ISE in this Microsoft Scripting Guys how-to article.<\/p>\n<p>&nbsp;<\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. One of the things I enjoy about using the Windows PowerShell console is the transcript feature. When I am playing around on the Windows PowerShell console, experimenting, trying out new ideas, and exploring ideas, it is great not to worry about losing any cool code I discover. In my Windows PowerShell console profile, I use the <a href=\"http:\/\/www.bing.com\/visualsearch?g=powershell_cmdlets&amp;form=SGEWEB#noun=78&amp;r=0\">Start-Transcript<\/a> Windows PowerShell cmdlet to start a transcript when I am working in the Windows PowerShell console. I even have a function I wrote, which automates this&mdash;it is in my Windows PowerShell console profile. The function is shown here.<\/p>\n<p style=\"padding-left: 30px\"><strong>Start-Trans function<\/strong><\/p>\n<p style=\"padding-left: 30px\"><span>function start-Trans([switch]$debug)<br \/>\n{<br \/>\n<span>&nbsp;<\/span># to see debuging information startTrans\n-debug <br \/>\n<span>&nbsp;<\/span>if($debug) <br \/>\n<span>&nbsp;&nbsp; <\/span>{ <br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>$debugPreference =\n&#8220;continue&#8221; <br \/>\n<span>&nbsp;&nbsp; <\/span>} #end if debug<br \/>\n<span>&nbsp;<\/span>$dte =\n[dateTime]::Get_Today().DayOfWeek.tostring()<br \/>\n<span>&nbsp;&nbsp; <\/span>write-debug $dte<br \/>\n<span>&nbsp;<\/span>$dte = $dte + &#8220;_&#8221; +\n[dateTime]::now.hour<br \/>\n<span>&nbsp;&nbsp; <\/span>write-debug $dte<br \/>\n<span>&nbsp;<\/span>if(([datetime]::now.toLocalTIme()) -match\n&#8220;AM&#8221;) <br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>{ <br \/>\n<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Write-debug &#8220;Inside if\n&#8230;&#8221;<br \/>\n<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$dte = $dte + &#8220;_AM&#8221;<br \/>\n<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>write-debug $dte <br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>} #end if&#8230;<br \/>\n<span>&nbsp;<\/span>else<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>{<br \/>\n<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>write-debug &#8220;Inside else\n&#8230;&#8221;<span>&nbsp; <\/span><br \/>\n<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$dte = $dte + &#8220;_PM&#8221;<br \/>\n<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>write-debug $dte<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>} #end else<br \/>\n<span>&nbsp;&nbsp; <\/span>write-debug &#8220;Starting transcript\n&#8230; c:\\trans\\$dte.txt&#8221;<br \/>\n<span>&nbsp;<\/span>start-transcript -path\n&#8220;c:\\trans\\$dte.txt&#8221;<br \/>\n} #end start-Trans<\/span><\/p>\n<p><span><br \/><\/span><\/p>\n<p>When I start the Windows PowerShell console, the transcript automatically starts, as shown in the following image. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2046.WES09251001_49FF8AD2.jpg\"><img decoding=\"async\" height=\"323\" width=\"554\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2625.WES09251001_thumb_253E4D8E.jpg\" alt=\"Image of transcript automatically starting\" border=\"0\" title=\"Image of transcript automatically starting\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>Any information I return to the Windows PowerShell console screen is logged to the log file. This is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5857.WES09251002_597276D4.jpg\"><img decoding=\"async\" height=\"355\" width=\"554\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6443.WES09251002_thumb_7EFBF435.jpg\" alt=\"Image of information logged to log file\" border=\"0\" title=\"Image of information logged to log file\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>Unfortunately, the Windows PowerShell ISE does not have a transcript command. The <strong>Start-Transcript<\/strong> command generates an error, which is shown here:<\/p>\n<p style=\"padding-left: 30px\"><span>PS C:\\Users\\ed.NWTRADERS&gt; Start-Transcript<br \/>\nStart-Transcript : This host does not support transcription.<br \/>\nAt line:1 char:17<br \/>\n+ Start-Transcript &lt;&lt;&lt;&lt; <br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>+ CategoryInfo<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: NotImplemented: (:)\n[Start-Transcript], PSNotSup <br \/>\n<span>&nbsp;&nbsp; <\/span>portedException<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>+ FullyQualifiedErrorId :\nNotSupported,Microsoft.PowerShell.Commands.Start <br \/>\n<span>&nbsp;&nbsp; <\/span>TranscriptCommand<\/span><\/p>\n<p>Using the Windows PowerShell ISE object model, it is possible to create a transcript command that will work inside the Windows PowerShell ISE. I decided to create two functions, even though we do not actually need both functions. The <strong>Get-LogNameFromDate<\/strong> function will create a text file in a specific location. The file name is based upon the current date and time. The time portion uses the hour, minute, and second. The date portion of the file name uses the year, month, and day. As is usually the case, the help information is much more involved than the code that actually does the work. <\/p>\n<p>The code that creates the file name for the log is shown here. I use parameter substitution to create the file name. The file name comprises four parts: the path, the name prefix, the time, and the extension. After the file name is created, the <strong>New-Item<\/strong> cmdlet is used to create the file. <\/p>\n<p style=\"padding-left: 30px\">$<strong><\/strong>$logname = &#8220;{0}\\{1}{2}.{3}&#8221; -f $path,$name, `<\/p>\n<p style=\"padding-left: 30px\"><span>\n<span>&nbsp;&nbsp;&nbsp; <\/span>(Get-Date -Format\nyyyyMMdd-HHmmss),&#8221;Txt&#8221;<br \/>\nNew-Item -Path $logname -ItemType file | out-null<\/span><\/p>\n<p>In the <strong>Start-ISETranscript<\/strong> function, the text that is in the output pane is obtained from the <strong>text<\/strong> property of the <strong>output<\/strong> object and is written to the log file. The thing that is strange about the <strong>text<\/strong> property of the <strong>output<\/strong> object is that it is only available while the script is running. When the script ceases to run, the property is not available. This means you cannot access the output pane text from the Windows PowerShell ISE command pane. This portion of the <strong>Start-ISETranscript<\/strong> function is shown here. <\/p>\n<p style=\"padding-left: 30px\">$psISE.CurrentPowerShellTab.Output.Text &gt;&gt; $logname<\/p>\n<p>The two functions are shown here. <\/p>\n<p style=\"padding-left: 30px\"><b>Windows PowerShell ISE transcript functions<\/b><\/p>\n<p style=\"padding-left: 30px\"><span>Function Get-logNameFromDate<br \/>\n{<br \/>\n<span>&nbsp; <\/span>&lt;#<br \/>\n<span>&nbsp;&nbsp; <\/span>.Synopsis<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>Creates a log name from date<br \/>\n<span>&nbsp;&nbsp; <\/span>.Description<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>This script creates a log from a\ndate. <br \/>\n<span>&nbsp;&nbsp; <\/span>.Example<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>Get-logNameFromDate -path\n&#8220;c:\\fso&#8221; -name &#8220;log&#8221;<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>Creates a file name like\nc:\\fso\\log20100914-122019.Txt but does not<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>create the file. It returns the file\nname to calling code.<br \/>\n<span>&nbsp;&nbsp; <\/span>.Example<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>Get-logNameFromDate -path\n&#8220;c:\\fso&#8221; -name &#8220;log&#8221; -Create<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>Creates a file name like\nc:\\fso\\log20100914-122019.Txt and<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>create the file. It returns the file\nname to calling code.<br \/>\n<span>&nbsp;&nbsp; <\/span>.Parameter path<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>path to log file<br \/>\n<span>&nbsp;&nbsp; <\/span>.Parameter name<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>base name of log file<br \/>\n<span>&nbsp;&nbsp; <\/span>.Parameter create<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>switch that determines whether log\nfile or only name is created<br \/>\n<span>&nbsp;&nbsp; <\/span>.inputs<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>[string]<br \/>\n<span>&nbsp;&nbsp; <\/span>.outputs<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>[string]<br \/>\n<span>&nbsp;&nbsp; <\/span>.Notes<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>NAME:<span>&nbsp;\n<\/span>Get-LogNameFromDate<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>AUTHOR: ed wilson, msft<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>LASTEDIT: 09\/10\/2010 16:58:06<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>KEYWORDS: parameter substitution,\nformat specifier, string substitution<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>HSG: WES-09-25-10<br \/>\n<span>&nbsp;&nbsp; <\/span>.Link<br \/>\n<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Http:\/\/www.ScriptingGuys.com<br \/>\n<span>&nbsp;<\/span>#Requires -Version 2.0<br \/>\n<span>&nbsp;<\/span>#&gt;<br \/>\n<span>&nbsp;<\/span>Param(<br \/>\n<span>&nbsp; <\/span>[string]$path = &#8220;c:\\fso&#8221;,<br \/>\n<span>&nbsp; <\/span>[string]$name = &#8220;log&#8221;,<br \/>\n<span>&nbsp; <\/span>[switch]$Create<br \/>\n<span>&nbsp;<\/span>)<br \/>\n<span>&nbsp;<\/span>$logname = &#8220;{0}\\{1}{2}.{3}&#8221; -f\n$path,$name, `<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>(Get-Date -Format\nyyyyMMdd-HHmmss),&#8221;Txt&#8221; if($create) <br \/>\n<span>&nbsp; <\/span>{ <br \/>\n<span>&nbsp;&nbsp; <\/span>New-Item -Path $logname -ItemType file\n| out-null<br \/>\n<span>&nbsp;&nbsp; <\/span>$logname<br \/>\n<span>&nbsp; <\/span>}<br \/>\n<span>&nbsp;<\/span>else {$logname}<br \/>\n} # end function get-lognamefromdate<\/p>\n<p>Function Start-iseTranscript<br \/>\n{<br \/>\n<span>&nbsp; <\/span>&lt;#<br \/>\n<span>&nbsp;&nbsp; <\/span>.Synopsis<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>This captures output from a script to\na created text file<br \/>\n<span>&nbsp;&nbsp; <\/span>.Example<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>Start-iseTranscript -logname\n&#8220;c:\\fso\\log.txt&#8221;<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>Copies output from script to file\nnamed xxxxlog.txt in c:\\fso folder<br \/>\n<span>&nbsp;&nbsp; <\/span>.Parameter logname<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>the name and path of the log file.<br \/>\n<span>&nbsp;&nbsp; <\/span>.inputs<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>[string]<br \/>\n<span>&nbsp;&nbsp; <\/span>.outputs<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>[io.file]<br \/>\n<span>&nbsp;&nbsp; <\/span>.Notes<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>NAME:<span>&nbsp;\n<\/span>Start-iseTranscript<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>AUTHOR: ed wilson, msft<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>LASTEDIT: 09\/10\/2010 17:27:22<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>KEYWORDS:<br \/>\n<span>&nbsp;&nbsp;&nbsp; <\/span>HSG: WES-09-25-10<br \/>\n<span>&nbsp;&nbsp; <\/span>.Link<br \/>\n<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Http:\/\/www.ScriptingGuys.com<br \/>\n<span>&nbsp;<\/span>#Requires -Version 2.0<br \/>\n<span>&nbsp;<\/span>#&gt;<br \/>\n<span>&nbsp; <\/span>Param(<br \/>\n<span>&nbsp;&nbsp; <\/span>[string]$logname =\n(Get-logNameFromDate -path &#8220;C:\\fso&#8221; -name &#8220;log&#8221; -Create)<br \/>\n<span>&nbsp; <\/span>)<br \/>\n<span>&nbsp; <\/span>$transcriptHeader = @&#8221;<br \/>\n**************************************<br \/>\nWindows PowerShell ISE Transcript Start<br \/>\nStart Time: $(get-date)<br \/>\nUserName: $env:username<br \/>\nUserDomain: $env:USERDNSDOMAIN<br \/>\nComputerName: $env:COMPUTERNAME<br \/>\nWindows version: $((Get-WmiObject win32_operatingsystem).version)<br \/>\n**************************************<br \/>\nTranscript started. Output file is $logname<br \/>\n&#8220;@<br \/>\n<span>&nbsp;<\/span>$transcriptHeader &gt;&gt; $logname<br \/>\n<span>&nbsp;<\/span>$psISE.CurrentPowerShellTab.Output.Text\n&gt;&gt; $logname<br \/>\n} #end function start-iseTranscript<\/span><\/p>\n<p>To use the <strong>Start-ISETranscript<\/strong> function, add the call to the function at the bottom of your script. The script does not have to be saved or have a name. This is shown in the following image. One thing to keep in mind is that the entire contents of the output pane will be written to the log file. This means that if you run the script two or three times and do not clear the output pane, you could have the results from several scripts in your transcript log. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2627.WES09251003_01C1A929.jpg\"><img decoding=\"async\" height=\"439\" width=\"554\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3113.WES09251003_thumb_27B7597F.jpg\" alt=\"Image of function in action\" border=\"0\" title=\"Image of function in action\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>The output of the <strong>Start-ISETranscript<\/strong> function is shown in the following image. As you can tell, the header to the transcript file is extremely similar to the second image shown above that was produced by the <strong>Start-Transcript<\/strong> cmdlet from the Windows PowerShell console. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2727.WES09251004_2DFE300D.jpg\"><img decoding=\"async\" height=\"435\" width=\"554\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1663.WES09251004_thumb_2CB9972E.jpg\" alt=\"Image of output of Start-ISETranscript function\" border=\"0\" title=\"Image of output of Start-ISETranscript function\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>We invite you to follow us 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 us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a>. See you tomorrow for another edition of the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/weekend+scripter\/\">Weekend Scripter<\/a>. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Create a transcript of commands from the Windows PowerShell ISE in this Microsoft Scripting Guys how-to article. &nbsp; Microsoft Scripting Guy Ed Wilson here. One of the things I enjoy about using the Windows PowerShell console is the transcript feature. When I am playing around on the Windows PowerShell console, experimenting, trying out new [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25,3,4,61,45,100],"class_list":["post-17011","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-displaying-output","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-powershell","tag-windows-powershell-ise"],"acf":[],"blog_post_summary":"<p>Summary: Create a transcript of commands from the Windows PowerShell ISE in this Microsoft Scripting Guys how-to article. &nbsp; Microsoft Scripting Guy Ed Wilson here. One of the things I enjoy about using the Windows PowerShell console is the transcript feature. When I am playing around on the Windows PowerShell console, experimenting, trying out new [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17011","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=17011"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17011\/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=17011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=17011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=17011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}