Press "Enter" to skip to content

Category: Powershell

Enabling Powershell’s Strict Mode

Patrick Gruenauer grabs the ruler:

PowerShell is very forgiving of errors. For example, if you call something that does not exist, then no error message is displayed. In this short article I want to show you how to make PowerShell a bit more strict with the strict mode.

Consider you are calling a variable that doesn’t exist. PowerShell will display no errors.

Granted, that laxity isn’t On Error Resume Next level bad, but Patrick shows us a way to toughen up the interpreter’s responses.

Comments closed

Combining CSV Files via Powershell

Chad Callihan smooshes files together:

I recently had a handful of CVS files that needed reviewed. Each CSV file was the same format, and while I could have opened them each individually to sort and review, I thought it would be much easier to combine them into one file. It was time to turn to PowerShell. Let’s look at a few examples of how PowerShell can be used to combine multiple CSV files into a single file.

A core assumption here is that the structure of each file—particularly the number of columns but also the semantic meaning of each column—is the same.

Comments closed

Deciding on When to Automate

Jeffrey Hicks shares some hard-earned wisdom:

I’ve been scripting and automating things since the days of DOS 3.3, beginning with batch files. It always felt like magic. I could cast a charm simply by typing a few characters on a keyboard. Naturally, my magic skills went from batch files to VBScript to PowerShell. Throughout it all, I’ve also had an internal decision tree regarding automation. Over the years, I’ve seen IT pros new to scripting and automation needlessly struggle. Often it is due to a deficiency in their decision tree. Today, I thought I’d help you nurture yours.

There’s a lot of good advice here about where the automation inflection point is, choosing the right tool, and performing research first before trying to jump into a project.

Comments closed

Checking if a TCP Port Is in Use

Tom Collins knocks on doors:

Question: SQL Server won’t start , so checked Event Viewer and getting the following message. 

Server TCP provider failed to listen on [ ‘any’ <ipv4> 50010]. Tcp port is already in use.

How can I check if the port is already in use and which other process or service  has locked the port and therefore not allowing SQL Server to start on designated port ?

Read on to see how you can use Powershell to find the answer on Windows.

Comments closed

Notifying when MCR Has New SQL Server Images

Andrew Pruski builds an alert:

A while back I wrote a post on how to retrieve the SQL Server images in the Microsoft Container Registry (MCR).

It’s pretty simple to check the MCR but what about automating that check to alert if there are new images present? Let’s have a look at one method of doing just that with a powershell script using the BurntToast module, and a scheduled task.

Click through for the process and keep those Docker images up to date.

Comments closed

Working with Enumerations in Powershell

Patrick Gruenauer counts the ways:

The enum statement can be used to declare an enumeration. Microsoft describes this statement as follows:

The enum statement allows you to create a strongly typed set of labels. That enumeration can be used in the code without having to parse or check for spelling errors.

Click through for more description, as well as an example of how to create, instantiate, and operate on enumerations.

Comments closed

Automating Power BI Premium Dataset Backup

Gilbert Quevauvilliers shares the first part of a two-part series:

The first part in this 2-part series I am going to explain how configure the Azure Runbook so that you can then re-use it for multiple different Power BI datasets.

I am confident that most people have more than one dataset that needs to be backed up.

Before starting, please make sure that you have connected your Power Per User or Premium App Workspace to Azure Storage

Read on for a high-level overview of how to create a runbook in Powershell, as well as the runbook code.

Comments closed

What to Use Instead of Get-EventLog

Emin Atac gets a scary message:

When you type the following

Get-EventLog-SourceMicrosoft-Windows-Kernel-General-Newest20-LogNameSystem-InstanceId1 | Select-ExpandPropertyMessage

You get

Possible detection of CVE: 2023-01-09T09:08:23.5000000Z
Additional Information: 2023-01-08T19:56:29.1492612Z
This Event is generated when an attempt to exploit a known vulnerability (2023-01-09T09:08:23.5000000Z) is detected.
This Event is raised by a User mode process.

Read on to learn what this error message means, why it pops up, and what you can do to avoid it in the future.

Comments closed

Notes on DBATools’s Get-DecryptedObject

Sean Gallardy explains an issue:

Let me start off by saying that DBATools is a great tool that is immensely helpful to the community, if you haven’t heard about it or tried it, please give it a shot! I personally believe that the SQL Server community is truly the best out there, with so many people helping each other and developing great, free, tools that benefit all. Having said that, I’ve been asked quite a few times to look into a “SQL Server Bug” decrypting data.

This is not an issue with SQL Server nor is it a bug/feature/whatever. It is, in fact, a bug in the source material for DBATools.

Read the whole thing.

Comments closed