Parsing EXE Output in PowerShell

I saw a post internally that asked this question: Anyone have a handy powershell script testing if the installed flyway version matches a specific string?

That seemed simple, but getting program output from PoSh wasn’t something I’ve tried. So I tackled the challenge and this is what happened.

Getting the Output

The first thing I wanted to do was actually figure out what the output of checking the version was from the CLI. I looked at the help and noticed a version verb. When I run that, I see a bunch of lines of output.

2024-09_0002

A lot of output. I need to parse a bunch of strings, and then find a line.

My first experiment was to run this to get a file with this output.

flyway version > fwversion.txt

Now, let’s parse this.

Parsing Content

It’s been awhile since I read stuff from a file, but I know Get-Content works to read the file. What about finding a line. I saw this post with an answer that noted Select-String can be used, so I decided to try that.

Here’s a first cut of code:

2024-09_0003

That didn’t work. However, with some experiments, I tried this code:

Get-content fwversion.txt | select-string 'Edition'

That worked.

2024-09_0004

Now, I’ll assign that to a variable with this code:

$a=Get-content fwversion.txt | select-string ‘Edition’

Next, I’ll split this string by spaces into a new variable with this:

$b = $a -split(‘ ‘)

Then I can evaluate the various element of $b. You can see below the first and third elements are what I’m interested in. Really the third. Remember, PoSh is zero-based.

2024-09_0005

That let’s me parse the output, but I don’t want to save a file. Now on to the next step.

Capturing the Output from a Program

One of the things I know you can do in a PoSh ptompt is run a program. The redirection operator allows you to move output. When I tried it, I couldn’t quite get the output I wanted, but I did find this post that helped. With that, I ran this code:

$a = & "flyway" --version  2>&1 | select-string 'Edition'

This runs Flyway, captures the output in a stream and then uses the code above to find the right line. I assign this to a variable.

Almost there.

Adding a Parameter and a Test

Since I want to call this from the CLI and pass i a parameter, I added a param() clause to my script and then a test that compares the version output from the flyway.exe to the parameter. That gest me this code:

param(
    [string]$versionToCheck=""
)
$a = & "flyway" --version  2>&1 | select-string 'Edition'
$b = $a -split(' ')
if ($b[3] -eq $versionToCheck)
{ Write-Output("$($b) installed")}
else {

Write-Output(“wrong version – $($b) installed”)
}


Now I can call this from the CLI and check things. It works well. At least for now.

2024-09_0001

I am certainly not a PoSh expert, but this short script took me about 15 minutes to write with a little research. Then a little testing and I sent it off to the requester. Haven’t heard any complaints, so I’m hoping this actually works for them.

Posted in Blog | Tagged , , | 2 Comments

Technology and Privacy

There can be a big divide among tech professionals on how they view data privacy. Some don’t worry too much, and some are very upset about the lack of data privacy and poor data handling practices from many organizations. Most people are probably in the middLe. I do know that every time I post about a Tesla, there are many people who mention the incredible amount of data Tesla collects, and how that makes them nervous.

Tesla discloses that they collect, and I get copies of my data with my own logger. I find the data interesting and I glance at it over time to look for trends. I’m still happy that my top destination in the last year (after home) is the gym 😉

Other car companies collect data on you and GM is in trouble in Texas. I suspect other companies do this, likely to learn more about how to build better cars, but also to get data they may be able to sell. The same thing likely happens with most of your data. Certainly, mobile phone companies collect lots of data, and I wouldn’t be surprised if a lot of your rentals/purchases/visits are being captured and sold to others from all sorts of vendors. Some of you might even be capturing usage data in your software that your customers might not like.

I don’t know how I feel about this. I do think disclosure is important but not in the form of some EULA or a contract that people have to click through. I think there ought to be choice of what data is being collected and how it’s used. Or if it can be used. While I often just accept or dismiss cookie banners, I do appreciate that I can refuse cookies and still use more websites. I ought to be able to easily opt out from most data collection from most companies. It really should be optional.

The world isn’t going back to analog devices and actions. Digital technology, with software invading most parts of your life, is here. I wouldn’t be surprised to find out most new appliances have a phone home feature that captures data and sends it back through unsecured wi-fi. A good reason to put a password on all your networks.

In portions of the world, there are restrictions on data and privacy. They could be stronger, and the laws could limit more of what companies can do. Many companies still make money or run fine.

They will be fine. Organizations always find ways to work within whatever system exists.

I think that would be a good thing for most of us if more data privacy restrictions were in place. However, I don’t know how most of us would even go about helping enact them.

Steve Jones

Listen to the podcast at Libsyn, Spotify, or iTunes.

Note, podcasts are only available for a limited time online.

Posted in Editorial | Tagged | Comments Off on Technology and Privacy

Monday Monitor Tips–Finding CUs for My Instance

How can I quickly get a CU patch for a system that’s out of date? I’ll discuss that situation.

You might think you get to patch every instance every few months, and you may be able to. But most of us have laggards in any decent-sized estate. Someone always wants to avoid patching, or skip patching on the day you’ve scheduled every other system.

This is part of a series of posts on Redgate Monitor. Click to see the other posts

Tracking Versions

The Estate page in Redgate Monitor contains quite a few different views of your entire estate. This section is designed to aggregate data across all the systems you are monitoring. If I look at https://monitor.red-gate.com/Estate/Versions, I see this as a default.

2024-08_0041

This gives me an overview of what SQL Server versions I’m monitoring. As you can see, our test estate has a mix of versions, from 2008R2 through 2022 and one Managed Instance. The counts are in the pie chart, and we can see how many are up to date in the bars to the right of each version. As you can see, lots of our estate needs patching.

I can also see at a glance for each version that the latest update is and its release date. The download link is a quick way to download the latest patch from Microsoft. We maintain this list and Redgate Monitor will update it on a regular basis.

When I scroll down, I see the details of individual instances. These are grouped, though I can change that with the toggle in the upper left. For each instance, I have the name and the major version,

2024-08_0042

The current status and the latest patch are listed next to each other, with an icon and color coding that let’s me know I need to upgrade (yellow up arrow) or I’m patched (green checkmark). I once again have the latest patch, linked to the MS article as well as text that let’s me know how out of date I am.  You can see these patches are a month old. Auditors are potentially OK with that.

2024-08_0043

However, for my 2012 instances, I’m way out of date. No excuse for that. We keep these firewalled and protected, and they are available here only for demonstration purposes.

2024-08_0045

To the right of this we have our support dates. If a date is past, we mark it with a triangle to let you know that you have unsupported versions. That may or may not be an issue for your organization.

2024-08_0044

Summary

This section of the Estate tab isn’t something I expect DBAs or sysadmins to check often, but I would schedule a reminder to do this quarterly. Knowing the state of our patching process is important, especially when there are security updates being released. We have had a few in the last year for SQL Server, and it is important to patch and apply those.

Seeing not only the status, but having an easy download link makes this a very handy tab that I wish I’d have had in quite a few jobs during the 90s and early 2000s. If you haven’t checked your estate tab in Redgate Monitor, you might do that today.

Redgate Monitor is a world class monitoring solution for your database estate. Download a trial today and see how it can help you manage your estate more efficiently.

Posted in Blog | Tagged , , , | 1 Comment

AI Sings the Blues

Quite a few of you aren’t thrilled or enamored by GenAI (Generative Artificial Intelligence) with things like ChatGPT or CoPilot. Some of you love it or find it fascinating. My guess is many of you are like me and you’re not quite sure how useful this is with a healthy dose of skepticism.

No matter how you feel, I find this piece on AI Blues fascinating to read. It talks about some of the problems with AI and how people are becoming less tolerant of the small errors that AIs make. I think people might be upset with some of the issues, but I also think these are types of things we might see in a colleague as well, and we might tolerate them for much longer than we think.

The thing in the piece that really caught my eye is that training models to make less errors might make them less creative. I don’t think they are very creative, but I do think part of the idea is that they might do something better than we could do, at least for those of us working in a space where we’re a beginner to intermediate (or advanced beginner). In many cases, we’d expect better output from a model.

The note about training not being often or in-depth enough as well is interesting. Perhaps some of the models ought to be trained separately, with some having a more specific focus, like learning Python and producing very few errors, or learning Python to produce interesting solutions to large scale problems even if there are some errors in the code.

I could see similarly more tightly trained models for other areas, such as marketing email or legal issues. Maybe we need a lot of different models tailored for different jobs. Of course, if companies are struggling to generate revenue on AI already (and I think they are), then can they afford to train and retrain specific models focused for smaller audiences?

Maybe, and maybe Moore’s law will help bail out some AI experiments, but I’m not sure. For now, I continue to experiment, and I think skilled tech people ought to do the same. I don’t think it will replace us, but I do think it can be a useful tool in many ways to help us become more productive.

Steve Jones

Posted in Editorial | Tagged | Comments Off on AI Sings the Blues