A few weeks ago, the Iron Scripter challenge was to write code to convert a short string into its numeric valuesusing the alphabet as it is laid out on a telephone. A number of solutions have already been shared in the comments on the original post. There are certainly a number of ways to meet…
Tag: Regular Expressions
Importing Pester Results into PowerShell
Last week, a PowerShell scripting challenge was posted on the Iron Scripter web site. The idea was that when you run a Pester test, you can save the results to a specially formatted XML file. Invoke-Pester C:\scripts\sample.test.ps1 -OutputFile d:\temp\results.xml -OutputFormat JUnitXml I get this result. The challenge was to write a PowerShell command that could…
Learn More about PowerShell and Regular Expressions
For many Windows-oriented IT Pros, and I used to be one of them, regular expressions was an arcane topic that was too hard to learn. And we never really had a compelling need to learn because we were busy clicky-clicking everything. Then came PowerShell and we discovered, or maybe rediscovered, a whole new way to…
Capturing Names with PowerShell and Regular Expressions
As you continue to learn and embrace PowerShell, you will eventually meet regular expressions. Hopefully many of you already have some fundamental knowledge. if not, the first place to start is by reading the help topic, about_regular_expressions In this article, I’m gong to introduce you to an advanced regular expression topic – named captures. I’ll…
Using Optimized Text Files in PowerShell
If you are like many IT Pros that I know, you often rely on text files in your PowerShell work. How many times have you used a text file of computernames with Get-Content and then piped to other PowerShell commands only to have errors. Text files are convenient, but often messy. Your text file might…
Scraping Sysinternals
Recently I was conversing with someone about my PowerShell code that downloads tools from the live Sysinternals site. If you search the Internet, you’ll find plenty of ways to achieve the same goal. But we were running into a problem where PowerShell was failing to get information from the site. From my testing and research…
More Fun with String Properties
The other day I posted an article about converting string properties that you might get from running a command line tool into a PowerShell named property. I was continuing to experiment with it. Here’s some code on how I could use it. $raw = qprocess $properties = $raw[0] -split “\s{2,}” | Convert-StringProperty $raw | select…
Convert a String to a PowerShell Property Name
Over the last few years I’ve written and presented a bit on the idea of turning command line tools into PowerShell tools. We have a lot of great CLI based tools that are still worth using. What I’ve done is come up with tools and techniques for turning their output into an object that can…
Friday Fun: Find File Locking Process with PowerShell
I was asked on Twitter this morning about a way to find out what process has a lock on a given file. I’m not aware of any PowerShell cmdlet that can do that but I figured there had to be a .NET way and if I could find a code sample I could put something…
Find and Replace Text with PowerShell
I’ve just finished up a series of tweets with a follower who had a question about finding and replacing a bit of data in a text file. In his case it was a web.config file but it really could be any text file that you can view in PowerShell. In PowerShell 3.0 and later this…
Convert Text to Object with PowerShell and Regular Expressions
A few weeks ago I was getting more familiar with named captures in regular expressions. With a named capture, you can give your matches meaningful names which makes it easier to access specific captures. The capture is done by prefixing your regular expression pattern with a name. PS C:\> “UNC is \\server01\public” -match “\\\\(?<servername>\w+)\\(?<sharename>\w+)” True…
Friday Fun with REST, Regex and Replacements
I just love using the web cmdlets that were introduced in PowerShell 3.0. One of the cmdlets I use the most is Invoke-RESTMethod. This isn’t because I’m dealing with sites that offer REST-ful services, but rather I like that the cmdlet does all the heavy lifting for me when I point it to an RSS…
PowerShell Scripting with [ValidatePattern]
I’ve been writing about a number of parameters attributes you can include in your PowerShell scripting to validate parameter values. Today I want to cover using a regular expression pattern to validate a parameter value. I’m going to assume you have a rudimentary knowledge of how to use regular expressions in PowerShell. If not, there…
Friday Fun Get Content Words
Recently I was tracking down a bug in script for a client. The problem turned out to be a simple typo. I could have easily avoided that by using Set-StrictMode, which I do now, but that’s not what this is about. What I realized I wanted was a way to look at all the for…
Create a Master PowerShell Online Help Page
As I hope you know, PowerShell cmdlets can include links to online help. This is very handy because it is much easier to keep online help up to date. To see online help for a cmdlet use the -online parameter. get-help get-wmiobject -online I decided to take things to another level and create an HTML…