{"id":2925,"date":"2013-09-06T00:01:00","date_gmt":"2013-09-06T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/09\/06\/windows-powershell-3-0-first-steps-part-5\/"},"modified":"2013-09-06T00:01:00","modified_gmt":"2013-09-06T00:01:00","slug":"windows-powershell-3-0-first-steps-part-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/windows-powershell-3-0-first-steps-part-5\/","title":{"rendered":"Windows PowerShell 3.0 First Steps: Part 5"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft Scripting Guy, Ed Wilson, shares a portion from his popular Microsoft Press book <em>Windows PowerShell 3.0 First Steps<\/em>.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today I want to share with you another portion from my new book, <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-3-0-First-Steps\/dp\/0735681007\/ref=sr_1_1?s=books&amp;ie=UTF8&amp;qid=1377624341&amp;sr=1-1&amp;keywords=powershell+3.0+first+steps\" target=\"_blank\">Windows PowerShell 3.0 First Steps<\/a>, which was recently released by Microsoft Press.<\/p>\n<p align=\"left\">To read the previous parts of this series, see:<\/p>\n<ul>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/09\/02\/windows-powershell-3-0-first-steps-part-1.aspx\" target=\"_blank\">Windows PowerShell 3.0 First Steps: Part 1<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/09\/02\/windows-powershell-3-0-first-steps-part-2.aspx\" target=\"_blank\">Windows PowerShell 3.0 First Steps: Part 2<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/09\/02\/windows-powershell-3-0-first-steps-part-3.aspx\" target=\"_blank\">Windows PowerShell 3.0 First Steps: Part 3<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/09\/02\/windows-powershell-3-0-first-steps-part-4.aspx\" target=\"_blank\">Windows PowerShell 3.0 First Steps: Part 4<\/a><\/li>\n<\/ul>\n<h2>Storing data in text files<\/h2>\n<p>One of the easiest methods to store data is to store the data in a text file. In the following image, the output from the <strong>Get-Volume<\/strong> function displays in the Windows PowerShell console. The output formats nicely in columns, and it contains essential information about the volumes on a Windows&nbsp;8 laptop.<\/p>\n<p class=\"AltText\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7585.hsg-9-6-13-1.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7585.hsg-9-6-13-1.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<h2>Redirect and append<\/h2>\n<p>The easiest way to store volume information obtained from the <strong>Get-Volume<\/strong> function is to redirect the output to a text file. Because several lines of information return from the function, it is best to redirect and append the outputted information. The redirect and append operator is two right arrows, one behind the other with no space in between them.<\/p>\n<p>The following script redirects and appends the information from the <strong>Get-Volume<\/strong> function to a text file that resides in the folder c:\\fso. The file, VolumeInfo.txt, does not have to exist. If it does not exist, it will be created, and the information written to the file. If the file does exist, the outputted data will append to the file. The command is shown here:<\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\">Get-Volume &gt;&gt;c:\\fso\\volumeinfo.txt<\/p>\n<p>When the command runs, nothing outputs to the Windows PowerShell console. The output, formatted as it appears in the Windows PowerShell console, writes to the target text file. The following image shows the volumeinfo.txt file that is created by redirecting and appending the results of the <strong>Get-Volume<\/strong> function from Windows&nbsp;8.<\/p>\n<p class=\"AltText\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2451.hsg-9-6-13-2.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2451.hsg-9-6-13-2.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>If you run the code that redirects and appends the information from the <strong>Get-Volume<\/strong> function to a text file that resides in the folder c:\\fso named volumeinfo.txt a second time, the information from <strong>Get-Volume<\/strong> writes to the bottom of the previously created text file.&mdash;that is, it appends to the file.<\/p>\n<p>This is a great way to produce simple logging. The following image shows the volume information appearing twice. In both cases, the values are identical. This shows that between the first time the <strong>Get-Volume<\/strong> command ran and the second time the <strong>Get-Volume<\/strong> ran, nothing changed.&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8424.hsg-9-6-13-3.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8424.hsg-9-6-13-3.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>This concludes my Windows PowerShell 3.0 First Steps book preview. Join me tomorrow when I will have a great post about remoting the cloud, written by Microsoft senior technical evangelist, Keith Mayer.<\/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><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shares a portion from his popular Microsoft Press book Windows PowerShell 3.0 First Steps. Microsoft Scripting Guy, Ed Wilson, is here. Today I want to share with you another portion from my new book, Windows PowerShell 3.0 First Steps, which was recently released by Microsoft Press. To read the [&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-2925","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, shares a portion from his popular Microsoft Press book Windows PowerShell 3.0 First Steps. Microsoft Scripting Guy, Ed Wilson, is here. Today I want to share with you another portion from my new book, Windows PowerShell 3.0 First Steps, which was recently released by Microsoft Press. To read the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2925","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=2925"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2925\/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=2925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}