What is infrastructure testing and how to do it with PowerShell?

Contents

Powershell logo

How we all try to do more with less with automation, sometimes we get to a point where we have a new problem. Now we are running so many scripts and processes that, in the end, we're not sure what it looks like “done”

If we are running a user provisioning script that creates an AD user (Active Directory), an Exchange mailbox or home folder, How do we truly know that the script did everything it was supposed to do? We cannot notice that an error was not thrown and we also check things afterwards. But if the script covers 1,000 users, there's no way it's viable. We also need to use test automation!!

What is infrastructure testing?

One way to automate this type of testing is with what is generally known as infrastructure testing.. What is infrastructure testing? It means any code that reads the configuration values ​​of various things in the IT environment and compares them to the expected values.

Some examples of infrastructure testing include:

  • “was that ad user created with the appropriate attributes?”
  • “The port 80 respond on my web server?”
  • “Is the DHCP service running?”

The discussion on infrastructure testing is much bigger than we have time in a single post, but i can give you a head start. As you start writing these tests, you will start to notice patterns; you will start to realize that you are repeatedly writing the same type of code, just applied to different things. Instead of copying and pasting all the time, you can share this code in the form of a PowerShell script or function.

Let's go through a couple of common script examples that I use to help make sure my infrastructure is set up correctly.

Testing a network port

A typical example of an infrastructure test is testing a network port. Because all network services open and listen on a particular port, a real proof of whether that service is “It is feasible that you have a workspace for graphical applications” or is not confirming that a specific port is enabled for remote computers. Despite this, to build this test, a good deal of knowledge about TCP is needed, UDP y .NET. Fortunately, you can use an existing community script called Test-NetworkPort.ps1. This script can be downloaded from the PowerShell Gallery through execution Install-Script -Name Test-NetworkPort.

Once downloaded, just call him using Test-NetworkPort.ps1 and pass a computer name and port to test.

PS > Test-NetworkPort.ps1 -ComputerName DC -Port 389
True

Depending on whether the port is listening or not, this script will return True O False. You can explore other parameters that this script has by reading the help associated with it through Get-Help Test-NetworkPort.ps1.

This script performs a proof about him infrastructure listening on a particular port.

DNS name resolution test

When opening a new machine, whether you rely on dynamic DNS to register the name or if you are explicitly creating a DNS record, you will need to make sure your name can be resolved. Con PowerShell, you can use a script that tries to fix a particular name and return True O False if it can be solved or not.

As with our port test example, we can also download this script from the PowerShell Gallery through Install-Script -Name Test-DnsNameResolution.

When the download is complete, just call Test-DnsNameResolution.ps1 with the name and DNS server you want to query.

PS> Test-DnsNameResolution.ps1 -Name DC.mylab.local -Server DC
False

If the script returns True, the DNS server DC can solve the name of DC.mylab.local. But, I would have returned False.

conclusion

The examples provided here are just two out of hundreds. The goal of this post is not to show you excuse me for infrastructure testing, but more to guide you in creating your own.

To create well-developed infrastructure tests, first it is necessary to establish what it means to be “It is feasible that you have a workspace for graphical applications” O “expected”, create a PowerShell script to find the current and expected state and make a choice from there.

Do not continue to manually confirm that your infrastructure is working as expected. Get started creating some PowerShell scripts and automate those mundane processes for you!!

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.