![]() Once that’s done, I perform the check to ensure it’s in the expected state. Once we do that, we can then build a simple Pester test using a describe block and an it block which contains code to check the service’s status. Let’s first ensure the service is stopped. For this example, the wuauserv service can either be stopped or started. To do that, I’ll first need to define all of the states the environment can be in before running the script. I’d like to test the results of this small script with Pester. What does pester you for something expression mean Definitions by the largest Idiom Dictionary. I’ll save this as a script called StartSRV1Service.ps1 Get-Service -ComputerName SRV1 -Name wuauserv | Start-Service Definition of pester you for something in the Idioms Dictionary. We’re changing the state of a single item, the wuauserv Windows server from stopped (if stopped) to started. Below is an example of the PowerShell script starting the service on a remote server SRV1.Īs you can see, the script is quite simple. After this PowerShell script is complete, I expect that service to be started. Let’s say that I have a PowerShell script that just starts a Windows service. This can be anything that you can check the state of with PowerShell and that’s a lot of stuff. Let’s create a simple infrastructure test with Pester.įirst of all, we need to figure out what we’re going to test. There are plenty of other resources out there for that. This isn’t an article covering how to use Pester. Pester TestsĪ Pester test can be broken down into a few main components a describe block and an it block. Infrastructure tests, in Pester, are essentially PowerShell code that’s executed by the Pester PowerShell module and built in a specific way known as a domain-specific language (DSL) that describes the desired state, has the code necessary to check that state and to compare the result. Does that file server have the expected folder hierarchy?.When I run this PowerShell script, does it create the right user account?.Does that server have the right software installed on it?.Pester was originally designed to build unit tests around PowerShell scripts but since it was built in PowerShell, many system administrators have adapted it to performing integration or infrastructure tests in a variety of different circumstances such as routine checks, part of larger automation scripts, or part of build and release pipelines to ensure any changes made to environments needed by software deployments happened as expected.Īn infrastructure test is a generic term for any kind of code that you write to test a current state against an expected state. How can you be sure what changed is what you expected? One way is to use the PowerShell testing framework, Pester. Perhaps, a coworker is making changes at the same time and they conflict. Applies to: Pester 3.4.0 When you crack open the Pester module, you find the New-Fixture function, which creates a script and test file pair, and the Invoke. When you do make changes, are you sure you changed the right setting? Are you sure that change you made didn’t affect something else you’re unaware of? Change management is a crucial part of managing infrastructure in an IT pro’s world. Changes can make infrastructure better or can bring it to its knees.
0 Comments
Leave a Reply. |