Scripting Blog

A place to learn about PowerShell and share stories of automation

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

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 Hey, AK. We apologize for taking so long to ...

How Can I Remove Blank Spaces Before and After a String Value?

Hey, Scripting Guy! We have a custom in-house application that writes data to a log file. The problem is that the data often has a bunch of blank spaces before and after it. How can I remove all the blank spaces that come before and after my data?-- KS Hey, KS. You might find this hard to believe, but the Scripting Guy who writes this ...

How Can I Truncate Names to a Maximum of 16 Characters?

Hey, Scripting Guy! How can I truncate names to a maximum of 16 characters?-- BN Hey, BN. Brace yourself: it’s time for another trip down memory lane. When one of the Scripting Guys was going to college, he took a temporary summer job with the Green Giant Corporation, working in the office that oversaw the asparagus harvest in eastern ...

How Can I Convert a DN to this Format: finance.fabrikam.com/Users?

Hey, Scripting Guy! How can I convert a DN to this format: finance.fabrikam.com/Users?-- CW Hey, CW. You know, this is a pretty good question; in fact, we should have used it for the Winter Scripting Games. Ah, but, on second thought, maybe it’s a good thing we didn’t use it. Why not? Well, because all the Scripting Games competitors ...

How Can I Extract a Series of Characters Found in the Middle of a String?

Hey, Scripting Guy! I have a series of strings that look something like this: xxxxyyyyyyxx. How can I extract just the y’s?-- JB Hey, JB. And, yes, it is a Friday. But, hey, it’s just a coincidence that we happened to pick an easy question on a Friday, the day we’re itching to get out of here and go home and spend the weekend watching...

Feedback usabilla icon