Docker Compose “is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.” In this post, I will show how you can work with Docker Compose.

To elaborate on that tweet, this Function spawned from a larger initiative that I am working on for a presentation I’m giving at PowerShell Summit 2018 in April. That presentation will be about a PowerShell Module I have built called PSLogging, which is a logging framework built using PowerShell Classes.

One of the items on my to-do list, which always seems to grow and not shrink, is to add a configuration component. This configuration component would allow someone to create a config.json or config.yml file that would be referenced when logging within their application/script/function/etc. Here is a quick example of what the configuration may (work in-progress) look like:

Within this configuration file I would allow someone to specify the “log level” and all the available formatting options. As you can see in the image above, one such configuration option is that ability to specify the datetime format, a filename, encoding, etc. But the point of this post is specifically about the datetime format option.

I needed (wanted) a way to identify if the provided format string in the datetime configuration option is an actual valid [DATETIME] format string value. If you are not familiar with this concept, then please see the below example when using the Get-Date Cmdlet:

To further explain, I will show you a snippet of PowerShell code and the corresponding Class that does exactly what I described above and it may shed some light on the “why”. Imagine you have a JSON configuration file, but it has multiple options available and only certain options are “mandatory”. You would first need to load the content from that JSON file and then convert it using the ConvertFrom-Json Cmdlet. The next step is that you would need to iterate through the configuration and identify (and verify) each piece of configuration before you rely on it, right? Here’s an example of just that:

As you can see, we loop through the first time and identify if the console setting was set, if it was then we would need to check and see if the passed in [datetime] format string is correct, if it is then set our console configuration (if you’re following along, let me tell you there are other forms of validation this is just an example). 🙂

Now, to show you the [DateTimeValidation] Class that is doing all the magic. Additionally, I have a ConsoleConfiguration Class and a LogLevel Enum but we won’t get into the details of those at this time:

To briefly explain, we call the [DateTimeValidation] Class from within our If statement above. This call then validates that our passed in [string] format is valid (or not) based on the current Culture/Globalization settings. Once the provided string data has been validated, then we can proceed to add it to our [ConsoleConfiguration] Class. The great thing about this class is that I can just reuse it, over and over and over.

Now, let’s get back to the actual function and not all this Class non-sense. I ported over the logic from a Class in my PSLogging Module because I thought it would be useful to validate this type of input. In #PowerShell, especially Advanced Functions, we learn/preach/teach that we should always validate our inputs and ensure our outputs are what the user expects – this is crucial in any language. If you are familiar with Parameter Validation on PowerShell Functions then this should come at no surprise to you. We should ALWAYS validate our data!

This function is no different. You may not have a use case for it now, and this is NOT revolutionary at all, but there may come a time when you need to validate those pesky string formatting rules and I hope this function helps out.

The easiest way to create an ADMX template is to build an ADM template first and then convert the latter with the help of Microsoft’s free ADMX Migrator tool.

Administrative templates let us create custom Group Policy settings. Administrative template files have two different versions. Windows Vista introduced templates with the .ADMX extension. These templates use an XML syntax and can be a lot more difficult to decipher and create by hand. On the other hand, templates with the .ADM extension are straightforward and have a simple syntax that allows you to create new Group Policy templates quickly.

With the AWS Tools for PowerShell, you can manage Amazon Elastic Compute Cloud (EC2), the service for virtual machines (EC2 instances) in Amazon’s cloud. Using Amazon’s PowerShell tools and the AWS API, we can create, manage, and deploy EC2 instances (VMs) from our console.

Please read my post about the AWS Tools for PowerShell where I talk about the minimum requirements to access AWS. To install the AWS Tools for PowerShell, open up a PowerShell console and run: