Scripting Blog [archived]

Formerly known as the "Hey, Scripting Guy!" blog

How Can I Append a Blank Line to a Text File, Then Append the Current Date and Time?

(image) Hey, Scripting Guy! How can I append a blank line to a text file, then append the current date and time?-- PL(image) (image) (image) Hey, PL. You know, back in the 1600s people were inordinately worried about witches and witchcraft. Fortunately, though, they developed a sure-fire test to determine whether or not someone was a witch...

How Can I Locate a Value in a Text File and Then Parse the Line of Text Where the Value Was Found?

(image) Hey, Scripting Guy! How can I open a CSV file, locate a value in column 1, then store the value in column 2 in a variable?-- THvdH(image) (image) (image) Hey, HvdH. We have to be honest with you, it’s a little difficult for the Scripting Guy who writes this column to stay focused on his work today. After all, tomorrow is one of the...

How Can I Extract Information Located Between Two Known Values in a Text File?

(image) Hey, Scripting Guy! In a text file, how can I extract the information that appears between the string HOSTNAME= and a blank space?-- B(image) (image) (image) Hey, B. You’ll have to pardon us if we seem a little sluggish today; we’re still recovering from all the fun and excitement of Windows PowerShell Week. What if you missed ...

How Can I Extract the Text Between the Header and Footer in a Text File?

(image) Hey, Scripting Guy! How can I extract the text between the header and footer in a text file?-- LL(image) (image) (image) Hey, LL. Before we answer your question we should point out that, depending on when you’re reading this, you might be missing Day 1 of Windows PowerShell Week. Even as we speak the lovely and talented Jean Ross ...

How Can I Split a String Only on Specific Instances of a Character?

(image) Hey, Scripting Guy! I have a series of string values that I need to convert to an array, splitting the value on the ampersand (&). However, if the ampersand is followed by amp (in other words, if the string is &amp) I don’t want to split the string at that point. How do I do that?-- AK(image) (image) (image) Hey, AK. We ...