{"id":15170,"date":"2020-12-03T13:45:36","date_gmt":"2020-12-03T12:45:36","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/"},"modified":"2020-12-03T13:45:36","modified_gmt":"2020-12-03T12:45:36","slug":"an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/","title":{"rendered":"An Introduction to Pester &#8211; Unit Testing and Infrastructure checks in PowerShell"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>If you never heard of it, <a href=\"https:\/\/github.com\/pester\/Pester\">Pester<\/a> is a PowerShell module, written in PowerShell.<br \/>\nIt&#8217;s a framework for writing and running <a href=\"https:\/\/en.wikipedia.org\/wiki\/Unit_testing\">unit tests<\/a>, integration tests, and also infrastructure checks as we will see in a moment.<br \/>\nPester is used for example to test <a href=\"https:\/\/github.com\/PowerShell\/PowerShell\/tree\/master\/test\/powershell\">PowerShell Core<\/a> and Pester itself.<\/p>\n<p>In this blog post, I&#8217;ll do a short introduction to Pester with Installation and basic checks examples.<\/p>\n<h3>Installation<\/h3>\n<p>Pester is shipped by default with Windows 10 and Windows Server 2016. The version installed is 3.4.<br \/>\nThe latest version is available in the PSGallery. It is currently version 5.1.<br \/>\nIf you have the 3.4 version installed and would like to update it you will face errors with Update-Module. You need to use the following command to get the latest version:<\/p>\n<pre class=\"brush: powershell; gutter: true; first-line: 1\">PS C:\\&gt; Install-Module -Name Pester -Force -SkipPublisherCheck\nPS C:\\&gt; Get-InstalledModule\n\nVersion    Name                                Repository           Description\n-------    ----                                ----------           -----------\n5.1.0      Pester                              PSGallery            Pester provides a framework for...\n<\/pre>\n<h3>PowerShell function example<\/h3>\n<p>I will now show you a very basic Pester test.<br \/>\nLet&#8217;s say I want to write a Pester test for the following PowerShell function.<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/1_GetReverseString.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-44916\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/1_GetReverseString.png\" alt=\"\" width=\"500\" height=\"240\"><\/a><\/p>\n<p>This is a very basic function that reverses the string characters. This is the output:<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/4_GetReverseStringOutput_resize.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-44925\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/4_GetReverseStringOutput_resize.png\" alt=\"\" width=\"428\" height=\"101\"><\/a><\/p>\n<div>Now that I have a working function I can start to write the Pester test.<\/div>\n<h3>Create a Pester Tests file<\/h3>\n<div>The Pester function New-Fixture will create a template file for me but you could definitely create it yourself.<br \/>\nBy convention, Pester test files should end with &#8220;Tests.ps1&#8221;.<\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-44935\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/2_NewFixture-1.png\" alt=\"\" width=\"800\" height=\"60\"><\/div>\n<div>The Tests file has been created.<\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-44936\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/GetItem.png\" alt=\"\" width=\"400\" height=\"161\">I already edited the file and wrote the test.<br \/>\nThis is what a Pester test looks like:<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/GetReverseStringTests-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-44929\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/GetReverseStringTests-1.png\" alt=\"\" width=\"800\" height=\"254\"><\/a><\/div>\n<div><\/div>\n<h3>Pester basics<\/h3>\n<p>Pester is very declarative and easy to read.<br \/>\nYou can ignore the first 3 rows in the Tests file, they came from the New-Fixture function and just dot sources the function to test into the PowerShell session.<\/p>\n<p>The main commands with Pester are Describe, It, Context, and Should.<\/p>\n<p><a href=\"https:\/\/pester.dev\/docs\/commands\/Describe\">Describe<\/a> is a block that contains tests. You will often have one Describe block for each function you want to test.<br \/>\n<a href=\"https:\/\/pester.dev\/docs\/commands\/Context\">Context<\/a> blocks are like Describe, they contain It blocks. They are optional and are useful to organize your test code.<br \/>\nThe <a href=\"https:\/\/pester.dev\/docs\/commands\/It\">It<\/a> block is the one that actually contains the test. The It block should have an expressive phrase describing the expected test outcome.<br \/>\nFinally, the <a href=\"https:\/\/pester.dev\/docs\/commands\/Should\">Should<\/a> command defines the test condition to be met. If the assertion is not met the test fails and an exception is thrown up. I used the -Be parameter. Many more are available like -BeFalse, -BeGreaterOrEqual, -BeLike, -Contain, etc.<\/p>\n<p>In this example the test is simple. I set the expected value that I should get and I compare it to the actual value returned by the function.<\/p>\n<h3>Running Pester Tests<\/h3>\n<div>Now let&#8217;s run the test itself with Invoke-Pester.<\/div>\n<div><a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/invoke-Pester-Script-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-45603\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/invoke-Pester-Script-1.png\" alt=\"\" width=\"700\" height=\"227\"><\/a><\/div>\n<div><\/div>\n<div>Also, running Invoke-Pester without any parameter will run all the &#8220;Tests.ps1&#8221; files in the current location.<\/div>\n<div><a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/5_InvokePester-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-44933\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/5_InvokePester-1.png\" alt=\"\" width=\"700\" height=\"229\"><\/a><\/div>\n<div><\/div>\n<div>So, everything is green. We can see that one test was performed and it Passed.<\/div>\n<div><\/div>\n<div>Now let&#8217;s say another developer worked on the Get-ReverseString function and the latest change introduced a bug. <a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/6_GetReverseString_bug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-44922\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/6_GetReverseString_bug.png\" alt=\"\" width=\"500\" height=\"216\"><\/a>Function behavior has changed and the Pester test will now throw a beautiful exception:<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/7_InvokePester_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-44930\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/7_InvokePester_2.png\" alt=\"\" width=\"700\" height=\"371\"><\/a><\/div>\n<div>What is great is all the details (in red color) we can get when a test fails.<\/div>\n<h3>Infrastructure Testing<\/h3>\n<p>Pester is often used by sysadmin to do infrastructure testing. Your environment changes frequently and you need to be sure that your infrastructure is aligned with your standard.<br \/>\nHere are a few examples of such tests. The test is done directly inside a Pester code block not using a function like I did previously.<\/p>\n<p>Check that my Windows Server Power Plan is set to High Performance.<\/p>\n<pre class=\"brush: powershell; gutter: true; first-line: 1\">Describe \"Power Plan\" {\n    $PowerPlan = (Get-CimInstance -ClassName Win32_PowerPlan -Namespace 'root\\cimv2\\power' | Where-Object IsActive).ElementName\n    It \"Should be set to High Performance\" {\n        $PowerPlan | Should -be \"High Performance\" -Because \"This Power Plan increases performance\"\n    }\n}<\/pre>\n<p>The best practice for SQL Server disks is to have an allocation unit size of 64 KB, here is the check:<\/p>\n<pre class=\"brush: powershell; gutter: true; first-line: 1\">Describe \"File Allocation Unit Size\" {    \n    $BlockSize = (Get-CimInstance -ClassName Win32_Volume | Where-Object DriveLetter -eq $SQLDisk).BlockSize\n    It \"Should be 64 KB\" {\n        $BlockSize | Should -Be 65536 -Because \"It is recommended to set a File Allocation Unit Size value to 64 KB on partitions where resides SQL Server data or log files\"\n    }\n}<\/pre>\n<p>Here I used the <a href=\"https:\/\/dbatools.io\/\">dbatools<\/a> command Get-DbaErrorLogConfig to get the number of files configured for my ErrorLog. My best practice is to have 30 files instead of 6 by default.<\/p>\n<pre class=\"brush: powershell; gutter: true; first-line: 1\">Describe \"SQL Server Error Log Files\" {\n    $errorLogCount = (Get-DbaErrorLogConfig -SqlInstance $SQLInstance).LogCount\n    It \"Should have Number of Log files set to 30\" {\n        $errorLogCount | Should -Be 30 -Because \"Best practices requires 30 logs files to perform daily recycling\"\n    }\n}<\/pre>\n<p>When all put together the output of the Tests looks like this:<br \/>\n<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/InfrastructureCheck_2-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-45622\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/InfrastructureCheck_2-1.png\" alt=\"\" width=\"700\" height=\"453\"><\/a>As you can see I can easily validate that my SQL Server infrastructure is configured as expected.<\/p>\n<h3>Code Coverage<\/h3>\n<p>Code Coverage is the percentage of lines of code that is tested by unit tests.<br \/>\nIt&#8217;s an indicator of how thoroughly your code has been tested. Having 100% coverage doesn&#8217;t mean that the code is bug-free, it just indicates that all your code is being executed during the test.<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/CodeCoverage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-45672\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/CodeCoverage.png\" alt=\"\" width=\"800\" height=\"243\"><\/a><\/p>\n<p>If I add some code to my Get-ReverseString.ps1 file, the -CodeCoverage functionality will tell me exactly what is not covered by tests:<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/GetHost.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-45674\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/GetHost.png\" alt=\"\" width=\"400\" height=\"306\"><\/a><\/p>\n<p><a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/CodeCoverage_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-45673\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/CodeCoverage_2.png\" alt=\"\" width=\"800\" height=\"301\"><\/a><\/p>\n<h3>Conclusion<\/h3>\n<p>This blog post was just to get you started on learning Pester. There are a lot more possibilities with Pester. I might cover some more advanced usages a future post like the <a href=\"https:\/\/pester.dev\/docs\/usage\/testdrive\">TestDrive<\/a> or <a href=\"https:\/\/pester.dev\/docs\/usage\/mocking\">Mocking<\/a>.<br \/>\nHere are some resources I&#8217;d recommend:<\/p>\n<ul>\n<li><a href=\"https:\/\/pester.dev\/\">Pester.dev<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/what-is-pester-and-why-should-i-care\/\">What is Pester and Why Should I Care?<\/a><\/li>\n<li><a href=\"https:\/\/app.pluralsight.com\/library\/courses\/pester-infrastructure-testing\/\">Pluralsight: Infrastructure Testing with Pester<\/a><\/li>\n<\/ul>\n<p>You can find all the code from this blog post on <a href=\"https:\/\/github.com\/relsna\/dba-toolbox\/tree\/main\/Blog\/An%20Introduction%20to%20Pester\">GitHub<\/a>.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Written by <a href=\"https:\/\/www.linkedin.com\/in\/steven-naudet-aa540158\/\">Steven Naudet<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction If you never heard of it, Pester is a PowerShell module, written in PowerShell. It&#8217;s a framework for writing and running unit tests, integration tests, and also infrastructure checks as we will see in a moment. Pester is used for example to test PowerShell Core and Pester itself. In this blog post, I&#8217;ll do&hellip;&nbsp;<\/p>\n","protected":false},"author":26,"featured_media":15171,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","neve_meta_reading_time":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[4133,99],"tags":[],"class_list":["post-15170","post","type-post","status-publish","format-standard","has-post-thumbnail","category-database","category-sql-server"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.9 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>An Introduction to Pester - Unit Testing and Infrastructure checks in PowerShell - dbi services Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An Introduction to Pester - Unit Testing and Infrastructure checks in PowerShell\" \/>\n<meta property=\"og:description\" content=\"Introduction If you never heard of it, Pester is a PowerShell module, written in PowerShell. It&#8217;s a framework for writing and running unit tests, integration tests, and also infrastructure checks as we will see in a moment. Pester is used for example to test PowerShell Core and Pester itself. In this blog post, I&#8217;ll do&hellip;&nbsp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi services Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dbiservices\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-03T12:45:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/invoke-Pester-Script-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1346\" \/>\n\t<meta property=\"og:image:height\" content=\"437\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Microsoft Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:site\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Microsoft Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/\"},\"author\":{\"name\":\"Microsoft Team\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/857c83b2f1d7d3e7c113ed40edf63294\"},\"headline\":\"An Introduction to Pester &#8211; Unit Testing and Infrastructure checks in PowerShell\",\"datePublished\":\"2020-12-03T12:45:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/\"},\"wordCount\":821,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/invoke-Pester-Script-1.png\",\"articleSection\":[\"Database\",\"SQL Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/\",\"name\":\"An Introduction to Pester - Unit Testing and Infrastructure checks in PowerShell - dbi services Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/invoke-Pester-Script-1.png\",\"datePublished\":\"2020-12-03T12:45:36+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/invoke-Pester-Script-1.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/invoke-Pester-Script-1.png\",\"width\":1346,\"height\":437},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"An Introduction to Pester &#8211; Unit Testing and Infrastructure checks in PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi services Blog\",\"description\":\"#BeSharing\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\",\"name\":\"dbi services\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"width\":512,\"height\":512,\"caption\":\"dbi services\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/dbiservices\\\/\",\"https:\\\/\\\/x.com\\\/dbiservices\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/dbi-services\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/dbiservices\"],\"description\":\"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.\",\"email\":\"info@dbi-services.com\",\"telephone\":\"+41 32 422 96 00\",\"legalName\":\"dbi services SA\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/857c83b2f1d7d3e7c113ed40edf63294\",\"name\":\"Microsoft Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/microsoft-square.png\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/microsoft-square.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/microsoft-square.png\",\"caption\":\"Microsoft Team\"},\"description\":\"Posts published under the Microsoft Team account are collective contributions by the dbi services Microsoft consultants. The practice covers SQL Server across its lifecycle, from installation, migration, and security to high availability with Always On and performance tuning, together with Azure data services and the Microsoft Business Intelligence stack, including Power BI. The team holds Microsoft certifications up to Expert level and operates customer platforms under service level agreements.\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/microsoft-team\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"An Introduction to Pester - Unit Testing and Infrastructure checks in PowerShell - dbi services Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/","og_locale":"en_US","og_type":"article","og_title":"An Introduction to Pester - Unit Testing and Infrastructure checks in PowerShell","og_description":"Introduction If you never heard of it, Pester is a PowerShell module, written in PowerShell. It&#8217;s a framework for writing and running unit tests, integration tests, and also infrastructure checks as we will see in a moment. Pester is used for example to test PowerShell Core and Pester itself. In this blog post, I&#8217;ll do&hellip;&nbsp;","og_url":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/","og_site_name":"dbi services Blog","article_publisher":"https:\/\/www.facebook.com\/dbiservices\/","article_published_time":"2020-12-03T12:45:36+00:00","og_image":[{"width":1346,"height":437,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/invoke-Pester-Script-1.png","type":"image\/png"}],"author":"Microsoft Team","twitter_card":"summary_large_image","twitter_creator":"@dbiservices","twitter_site":"@dbiservices","twitter_misc":{"Written by":"Microsoft Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/"},"author":{"name":"Microsoft Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/857c83b2f1d7d3e7c113ed40edf63294"},"headline":"An Introduction to Pester &#8211; Unit Testing and Infrastructure checks in PowerShell","datePublished":"2020-12-03T12:45:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/"},"wordCount":821,"commentCount":0,"publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/invoke-Pester-Script-1.png","articleSection":["Database","SQL Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/","url":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/","name":"An Introduction to Pester - Unit Testing and Infrastructure checks in PowerShell - dbi services Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/invoke-Pester-Script-1.png","datePublished":"2020-12-03T12:45:36+00:00","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/invoke-Pester-Script-1.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/04\/invoke-Pester-Script-1.png","width":1346,"height":437},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/an-introduction-to-pester-unit-testing-and-infrastructure-checks-in-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"An Introduction to Pester &#8211; Unit Testing and Infrastructure checks in PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi services Blog","description":"#BeSharing","publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.dbi-services.com\/#organization","name":"dbi services","url":"https:\/\/www.dbi-services.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","width":512,"height":512,"caption":"dbi services"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/dbiservices\/","https:\/\/x.com\/dbiservices","https:\/\/www.linkedin.com\/company\/dbi-services\/","https:\/\/www.youtube.com\/user\/dbiservices"],"description":"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.","email":"info@dbi-services.com","telephone":"+41 32 422 96 00","legalName":"dbi services SA"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/857c83b2f1d7d3e7c113ed40edf63294","name":"Microsoft Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/12\/microsoft-square.png","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/12\/microsoft-square.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/12\/microsoft-square.png","caption":"Microsoft Team"},"description":"Posts published under the Microsoft Team account are collective contributions by the dbi services Microsoft consultants. The practice covers SQL Server across its lifecycle, from installation, migration, and security to high availability with Always On and performance tuning, together with Azure data services and the Microsoft Business Intelligence stack, including Power BI. The team holds Microsoft certifications up to Expert level and operates customer platforms under service level agreements.","url":"https:\/\/www.dbi-services.com\/blog\/author\/microsoft-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/15170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=15170"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/15170\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media\/15171"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=15170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=15170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=15170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}