Last active
May 1, 2022 20:12
-
-
Save markwragg/cb07238c1364bffa37c10917c7561625 to your computer and use it in GitHub Desktop.
Powershell pester script with various examples of using pester for operational validation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Describe 'My process checks' { | |
| Context 'Checking essential Windows processes are running' { | |
| It 'winlogon.exe is running' { | |
| get-process -Name 'winlogon' | Should be $true | |
| } | |
| } | |
| $CPUThreshold = 10 | |
| Context "Checking for processes using > $CPUThreshold% CPU" { | |
| $CpuCores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors | |
| $Samples = (Get-Counter “\Process(*)\% Processor Time” -ErrorAction SilentlyContinue).CounterSamples | |
| $Samples | Select InstanceName,@{Name=”CPU”;Expression={[Decimal]::Round(($_.CookedValue / $CpuCores), 2)}} ` | |
| | Sort-Object InstanceName ` | |
| | Where-Object {$_.InstanceName -ne "idle" -and $_.InstanceName -ne "_total"} ` | |
| | ForEach-Object { | |
| It "Process $($_.InstanceName) is using $($_.CPU)% CPU" { | |
| $_.CPU | Should Not BeGreaterThan 10 | |
| } | |
| } | |
| } | |
| } | |
| Describe 'Weird science checks' { | |
| Context 'Checking for the impossible' { | |
| It 'It should be opposite day' { | |
| $true | Should be $false | |
| } | |
| } | |
| } | |
| Describe 'Day of the week check' { | |
| $WeekDays = "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday" | |
| $WeekDays | ForEach-Object { | |
| It "Today should be $_" { | |
| (get-date).DayOfWeek | Should be $_ | |
| } | |
| } | |
| } | |
| Describe 'Operating System check' { | |
| It 'C:\Windows folder exists' { | |
| 'C:\Windows' | Should Exist | |
| } | |
| It 'C:\Linux folder does not exist' { | |
| 'C:\Linux' | Should Not Exist | |
| } | |
| } | |
| Describe 'Windows service check' { | |
| Get-Service -DisplayName "Windows*" | ForEach-Object { | |
| It "The $($_.DisplayName) service should be running" { | |
| $_.Status | Should be 'Running' | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Blog: https://wragg.io/getting-started-with-pester-for-operational-testing/