It has been a while since my last Friday Fun post. These are articles that use PowerShell in fun and off-beat ways. The goal is to demonstrate techniques and concepts not necessarily give you something ready for production. Today, I’m going to modify PowerShell output to hide, or redact, potentially sensitive information. I might want…
Tag: regex
Friday Fun: PowerShell Weather Widget
Recently, someone on Twitter turned me on to an resource that could be used in a PowerShell session to display weather information. This is apparently a well-established and well-regarded source. Once I worked out the basics, I naturally wanted to see what else I could do it with. Here’s what I came up with. Everything…
Sending Files to Your Browser with PowerShell
Over the course of the last year I’ve been using markdown files much more, especially as part of the Platyps module. Even though I have a markdown editor and I can also preview files in VS Code, sometimes I want to see the file in my browser which has a markdown viewer plugin. Or I…
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…
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: Expand Environmental Variables in PowerShell Strings
This week I was working on a project that involved using the %PATH% environmental variable. The challenge was that I have some entries that look like this: %SystemRoot%\system32\WindowsPowerShell\v1.0\. When I try to use that path in PowerShell, it complains because it doesn’t expand %SystemRoot%. What I needed was a way to replace it with the…
Get IP Addresses with PowerShell
In celebration of World IPv6 Day, I thought I’d post a little PowerShell code to return IP addresses for a computer. This information is stored in WMI with the Win32_NetworkAdapterConfiguration class. This class will return information about a number of virtual adapters as well so I find it easier to filter on the IPEnabled property….
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…
Convert Transcript to Script
During my PowerShell scripting best practices at Techmentor last week I mentioned a function I had to convert a PowerShell transcript to a script file. Since there’s very little difference between an interactive session and a script, parsing the transcript can yield 80% or more of a script very quickly. I wrote such a function…