{"id":2452,"date":"2014-06-16T08:00:41","date_gmt":"2014-06-16T06:00:41","guid":{"rendered":"http:\/\/www.razumny.no\/?p=2452"},"modified":"2014-05-25T14:08:26","modified_gmt":"2014-05-25T12:08:26","slug":"script-output-to-file-append-v-replace","status":"publish","type":"post","link":"https:\/\/www.razumny.no\/?p=2452","title":{"rendered":"Script output to file: Append -v- Replace"},"content":{"rendered":"<p>By default, when running a script, the output is shown to you in the command line interface. Most of the time, that is exactly what you want. Some times,\u00a0though, you are more interested in logging than in real-time data. The solution is to have the output sent to a file.<\/p>\n<p>As an example, imagine the following: You want to see where the traffic to a server ends, so you run a traceroute to find out. Normally, the command would like like this: <code>tracert server.dom<\/code><\/p>\n<p>Here&#8217;s\u00a0what you would use to route the output to a text file: <code>tracert server.dom &gt; textfile.txt<\/code>.<\/p>\n<p>Now, that&#8217;s all well and good, until you want to add more logs to the same file. The problem is that a single &gt; will replace the contents of the file in question with the new information. To append, rather than replace, use a double &gt;, like so:\u00a0<code>tracert server.dom &gt;&gt; textfile.txt<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default, when running a script, the output is shown to you in the command line interface. Most of the time, that is exactly what you want. Some times,\u00a0though, you are more interested in logging than in real-time data. The solution is to have the output sent to a file. As an example, imagine the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[615],"tags":[],"class_list":["post-2452","post","type-post","status-publish","format-standard","hentry","category-how-to-2"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p2ukSU-Dy","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":5270,"url":"https:\/\/www.razumny.no\/?p=5270","url_meta":{"origin":2452,"position":0},"title":"PowerShell: Building a script to find all members of several given groups","author":"Aleksander Nordgarden-R\u00f8dner","date":"16\/09\/2019","format":false,"excerpt":"Last week, I showed you how I find all the nested members of a specified group. When we get requests for such audits, however, they usually specify doing so for a number of groups. Now, we could of course do it, one group at a time, adding information to our\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5451,"url":"https:\/\/www.razumny.no\/?p=5451","url_meta":{"origin":2452,"position":1},"title":"PowerShell: Pipe output to CSV file","author":"Aleksander Nordgarden-R\u00f8dner","date":"11\/05\/2020","format":false,"excerpt":"Last week, I showed you how to get specific properties for all users in a given OU. Knowing that the output of that query quickly gets hard to navigate, wanting to remove the extraneous data that the customer didn't request, and assuming that they wanted to manipulate the data, I\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6979,"url":"https:\/\/www.razumny.no\/?p=6979","url_meta":{"origin":2452,"position":2},"title":"Powershell: A script to find all members of several groups refined","author":"Aleksander Nordgarden-R\u00f8dner","date":"07\/11\/2022","format":false,"excerpt":"One of the scripts that I use most often is the one I wrote about back in September of 2019. Usually, I only run it for up to ten or so groups, so it's not a big problem to simply swap out the group name, rince and repeat. Recently, however,\u2026","rel":"","context":"In &quot;How To&quot;","block_context":{"text":"How To","link":"https:\/\/www.razumny.no\/?cat=615"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4687,"url":"https:\/\/www.razumny.no\/?p=4687","url_meta":{"origin":2452,"position":3},"title":"Batch replace file extension of all files in a folder","author":"Aleksander Nordgarden-R\u00f8dner","date":"30\/07\/2018","format":false,"excerpt":"From time to time, I need to quickly change the file extension of all files in a folder. While there are tools that can do that for you (one of which I've written about previously), if you need to append the same file extension to all files in a folder,\u2026","rel":"","context":"In &quot;How To&quot;","block_context":{"text":"How To","link":"https:\/\/www.razumny.no\/?cat=615"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/rename.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2485,"url":"https:\/\/www.razumny.no\/?p=2485","url_meta":{"origin":2452,"position":4},"title":"List user home folder size","author":"Aleksander Nordgarden-R\u00f8dner","date":"30\/06\/2014","format":false,"excerpt":"Users\u00a0tend to store all kinds of crud on their network home folders, which can be a constant source of frustration for SysAdmins. Luckily, it is fairly easy to\u00a0get a list of the size of each folder, using a Powershell script. The script has already been made for us. It\u00a0is discussed\u2026","rel":"","context":"In &quot;How To&quot;","block_context":{"text":"How To","link":"https:\/\/www.razumny.no\/?cat=615"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5265,"url":"https:\/\/www.razumny.no\/?p=5265","url_meta":{"origin":2452,"position":5},"title":"Building a script to find all members of a given group","author":"Aleksander Nordgarden-R\u00f8dner","date":"09\/09\/2019","format":false,"excerpt":"Some time ago, I was asked to provide a list of everyone with access to a specific system. After communicating with the client, it transpired that they were particularly interested in knowing who were the members of a set of Active Directory groups. While this can be done manually, I\u2026","rel":"","context":"In &quot;How To&quot;","block_context":{"text":"How To","link":"https:\/\/www.razumny.no\/?cat=615"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/2452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2452"}],"version-history":[{"count":1,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/2452\/revisions"}],"predecessor-version":[{"id":2455,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/2452\/revisions\/2455"}],"wp:attachment":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}