# Pester

**URL:** https://forums.powershell.org/c/pester/8.md

[Latest](https://forums.powershell.org/latest.md) · [Categories](https://forums.powershell.org/categories.md)

---

## [About the Pester category](https://forums.powershell.org/t/about-the-pester-category/13)

<div class="topic-metadata">

**Author:** [@system](https://forums.powershell.org/u/system)\
**Replies:** 0\
**Last updated:** [February 19, 2021, 10:58am UTC](https://forums.powershell.org/t/about-the-pester-category/13 "2021-02-19T10:58:28Z")

</div>

Ask all the Pester related questions in this category. Be sure to look at Pester - The ubiquitous test and mock framework for PowerShell | Pester, where everything about pester is documented.

---

## [How do I share variables across run and discovery?](https://forums.powershell.org/t/how-do-i-share-variables-across-run-and-discovery/24941)

<div class="topic-metadata">

**Author:** [@BalassaMarton](https://forums.powershell.org/u/BalassaMarton)\
**Replies:** 0\
**Last updated:** [October 30, 2024, 11:33am UTC](https://forums.powershell.org/t/how-do-i-share-variables-across-run-and-discovery/24941 "2024-10-30T11:33:29Z")

</div>

I want to declare some variables and use them in It blocks values for -ForEach mocks defined inside BeforeAll/BeforeEach This is my initial script. Only the first test passes. BeforeAll { function MockableFunctio…

---

## [Weird behaviour - mock hangs when being called twice](https://forums.powershell.org/t/weird-behaviour-mock-hangs-when-being-called-twice/24890)

<div class="topic-metadata">

**Author:** [@dandraka](https://forums.powershell.org/u/dandraka)\
**Replies:** 1\
**Last updated:** [October 18, 2024, 12:24pm UTC](https://forums.powershell.org/t/weird-behaviour-mock-hangs-when-being-called-twice/24890 "2024-10-18T12:24:35Z")

</div>

Hi all I’m assigned to write a bunch of tests on an existing codebase and a number of my tests hang. The code, simplified to show the issue, is as follows: File MySharepointModule.ps1 : function Update-SharepointList…

---

## [Error on Azure Storage Tables using Peter Test Framework by adding PowerShell commands](https://forums.powershell.org/t/error-on-azure-storage-tables-using-peter-test-framework-by-adding-powershell-commands/24769)

<div class="topic-metadata">

**Author:** [@sreekanchu](https://forums.powershell.org/u/sreekanchu)\
**Replies:** 1\
**Last updated:** [September 19, 2024, 8:54pm UTC](https://forums.powershell.org/t/error-on-azure-storage-tables-using-peter-test-framework-by-adding-powershell-commands/24769 "2024-09-19T20:54:26Z")

</div>

I’m getting error while trying to list the azure storage tables using Pester framework. The same commands in PowerShell are working fine. My requirement is I want to convert the PowerShell commands as a test in Pester Te…

---

## [Seeking Guidance on Mocking Azure Commands in Pester Tests for PowerShell Class](https://forums.powershell.org/t/seeking-guidance-on-mocking-azure-commands-in-pester-tests-for-powershell-class/23863)

<div class="topic-metadata">

**Author:** [@fslef](https://forums.powershell.org/u/fslef)\
**Replies:** 4\
**Last updated:** [April 18, 2024, 8:16pm UTC](https://forums.powershell.org/t/seeking-guidance-on-mocking-azure-commands-in-pester-tests-for-powershell-class/23863 "2024-04-18T20:16:40Z")

</div>

Hi everyone, I’m running into a recurring issue when running Pester tests on a PowerShell class that interacts with Azure resources, specifically with Get-AzResource. The tests fail with an error indicating a need to lo…

---

## [Run certain tests at different "time"](https://forums.powershell.org/t/run-certain-tests-at-different-time/23843)

<div class="topic-metadata">

**Author:** [@onegreatusa](https://forums.powershell.org/u/onegreatusa)\
**Replies:** 1\
**Last updated:** [March 27, 2024, 6:10am UTC](https://forums.powershell.org/t/run-certain-tests-at-different-time/23843 "2024-03-27T06:10:32Z")

</div>

Hello, I am a newbie and start to investigate Pester for our use case below. Use case: We have an automation process that creates VMs. Throughout the process, where we have multiple phases, depending on where we are …

---

## [Pester first run](https://forums.powershell.org/t/pester-first-run/23015)

<div class="topic-metadata">

**Author:** [@jjakerr](https://forums.powershell.org/u/jjakerr)\
**Replies:** 4\
**Last updated:** [October 19, 2023, 8:20pm UTC](https://forums.powershell.org/t/pester-first-run/23015 "2023-10-19T20:20:22Z")

</div>

Hi, new to using pester and just trying the initial test script but getting the following error and no idea what it means. Any ideas ? \[-\] Discovery in C:\\users\\\*\*\*\*\*\*\*\*\\pester\\tests\\worldclockapi.tests.ps1 failed with…

---

## [Pester Testing for Module](https://forums.powershell.org/t/pester-testing-for-module/22211)

<div class="topic-metadata">

**Author:** [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Replies:** 0\
**Last updated:** [April 26, 2023, 1:16pm UTC](https://forums.powershell.org/t/pester-testing-for-module/22211 "2023-04-26T13:16:07Z")

</div>

Testing a large Powershell module with Pester 5.4.0, which is my first opportunity to leverage Pester. Many of the blogs were for older versions of Pester and version 5 is quite different in layout and scopes. This API…

---

## [In search for someone to update my pester test script](https://forums.powershell.org/t/in-search-for-someone-to-update-my-pester-test-script/21132)

<div class="topic-metadata">

**Author:** [@metablaster](https://forums.powershell.org/u/metablaster)\
**Replies:** 1\
**Last updated:** [December 10, 2022, 3:21pm UTC](https://forums.powershell.org/t/in-search-for-someone-to-update-my-pester-test-script/21132 "2022-12-10T15:21:16Z")

</div>

Hello guys, I suspect it’s not appropriate to ask for such kind of help but I will do it anyway because I’m not asking you to write code for me since I already have the code… I have pester tests script which spans some …

---

## [Pester Testcase for xml data](https://forums.powershell.org/t/pester-testcase-for-xml-data/20357)

<div class="topic-metadata">

**Author:** [@sneha](https://forums.powershell.org/u/sneha)\
**Replies:** 3\
**Last updated:** [September 8, 2022, 4:42am UTC](https://forums.powershell.org/t/pester-testcase-for-xml-data/20357 "2022-09-08T04:42:43Z")

</div>

\<mainheading\> \<ruled\> \<ruleid=1’ title=‘m’\> \</ruled\> \</mainheading\> I have one xml file having following structure.Aim is to design pester testcase in powershell which take ruleid as input from this xml and verify corre…

---

## [ConvertFrom-JSON: Cannot bind argument to parameter 'InputObject' because it is null](https://forums.powershell.org/t/convertfrom-json-cannot-bind-argument-to-parameter-inputobject-because-it-is-null/19698)

<div class="topic-metadata">

**Author:** [@jinkang23](https://forums.powershell.org/u/jinkang23)\
**Replies:** 1\
**Last updated:** [June 23, 2022, 6:04pm UTC](https://forums.powershell.org/t/convertfrom-json-cannot-bind-argument-to-parameter-inputobject-because-it-is-null/19698 "2022-06-23T18:04:14Z")

</div>

Hello, can anyone tell me what I am doing wrong here? Here’s a script I want to test using Pester (e.g. run3.ps1): using namespace System.Net param($Subscription) $ok = $true $errorMsg = "" $status = "In Progress" Wri…

---

## [Possible help for structuring Pester tests](https://forums.powershell.org/t/possible-help-for-structuring-pester-tests/19581)

<div class="topic-metadata">

**Author:** [@russtym](https://forums.powershell.org/u/russtym)\
**Replies:** 0\
**Last updated:** [June 13, 2022, 8:56am UTC](https://forums.powershell.org/t/possible-help-for-structuring-pester-tests/19581 "2022-06-13T08:56:03Z")

</div>

Hi, I thought this link might be useful. It’s a basic setup of how to structure Pester tests. It’s simple but does works. See if it helps? if you are new to Pester might be useful? https://realworldit.net/archives/820 …

---

## [Brand new to Pester - should be an array](https://forums.powershell.org/t/brand-new-to-pester-should-be-an-array/19421)

<div class="topic-metadata">

**Author:** [@Ricker\_Janette\_M](https://forums.powershell.org/u/Ricker_Janette_M)\
**Replies:** 0\
**Last updated:** [May 25, 2022, 8:34pm UTC](https://forums.powershell.org/t/brand-new-to-pester-should-be-an-array/19421 "2022-05-25T20:34:31Z")

</div>

I am brand new to Pester and cannot for the life of me find any documentation on how to test a variable is of a certain type. describe 'All Pester Tests' { it 'gets an array of all webs in the site collection' { …

---

## [Can I get a mock's name from inside the mock?](https://forums.powershell.org/t/can-i-get-a-mocks-name-from-inside-the-mock/19263)

<div class="topic-metadata">

**Author:** [@chscott](https://forums.powershell.org/u/chscott)\
**Replies:** 1\
**Last updated:** [May 7, 2022, 7:07am UTC](https://forums.powershell.org/t/can-i-get-a-mocks-name-from-inside-the-mock/19263 "2022-05-07T07:07:16Z")

</div>

In a normal function, you can use $MyInvocation.MyCommand to get the function’s name, but this returns $null in a mock. Is there any way to get the mock’s name in a similar manner?

---

## [Where can I find this option run Tests | Debug Tests](https://forums.powershell.org/t/where-can-i-find-this-option-run-tests-debug-tests/19093)

<div class="topic-metadata">

**Author:** [@GVK](https://forums.powershell.org/u/GVK)\
**Replies:** 3\
**Last updated:** [April 15, 2022, 11:38am UTC](https://forums.powershell.org/t/where-can-i-find-this-option-run-tests-debug-tests/19093 "2022-04-15T11:38:12Z")

</div>

I am using VS Code. I did install pester extension, can anyone help me where can i can enable the below option for pester tests in VS Code. I want the Run tests | debug tests enabled . Thank you.

---

## [Need some help fixing - Pester Test for unregister server](https://forums.powershell.org/t/need-some-help-fixing-pester-test-for-unregister-server/19060)

<div class="topic-metadata">

**Author:** [@GVK](https://forums.powershell.org/u/GVK)\
**Replies:** 1\
**Last updated:** [April 11, 2022, 1:52pm UTC](https://forums.powershell.org/t/need-some-help-fixing-pester-test-for-unregister-server/19060 "2022-04-11T13:52:06Z")

</div>

\#---------------------------------------------------------- # Un-register the SQL Server database instance. #---------------------------------------------------------- if ($newDbId) { $registrationURL = $baseURL + "dat…

---

## [Best practises on How to do Unit / Integration Testing using Pester when APIs Calling is involved](https://forums.powershell.org/t/best-practises-on-how-to-do-unit-integration-testing-using-pester-when-apis-calling-is-involved/19058)

<div class="topic-metadata">

**Author:** [@GVK](https://forums.powershell.org/u/GVK)\
**Replies:** 2\
**Last updated:** [April 11, 2022, 8:26am UTC](https://forums.powershell.org/t/best-practises-on-how-to-do-unit-integration-testing-using-pester-when-apis-calling-is-involved/19058 "2022-04-11T08:26:05Z")

</div>

Hi , I am pretty new to Pester Unit / Integration testing. Currently I have a powershell script which has Invoke-RestMethod included for calling a API. There are other commands like Write-Verbose and someother function…

---

## [How to mock a cmdlet within ForEach-Object -Parallel](https://forums.powershell.org/t/how-to-mock-a-cmdlet-within-foreach-object-parallel/17570)

<div class="topic-metadata">

**Author:** [@Marc013](https://forums.powershell.org/u/Marc013)\
**Replies:** 0\
**Last updated:** [September 20, 2021, 1:02pm UTC](https://forums.powershell.org/t/how-to-mock-a-cmdlet-within-foreach-object-parallel/17570 "2021-09-20T13:02:17Z")

</div>

Can anyone explain me how to mock cmdlet Update-AzTag within a ForEach-Object -Parallel ScriptBlock? I’m trying to mock the cmdlet, which is within a ForEach-Object -Parallel ScriptBlock (see Update-ResourceTag). Howev…

---

## [Private Module Function Not Found When Running All Test Scripts and Piping Multiple Objects](https://forums.powershell.org/t/private-module-function-not-found-when-running-all-test-scripts-and-piping-multiple-objects/17277)

<div class="topic-metadata">

**Author:** [@jsmyth](https://forums.powershell.org/u/jsmyth)\
**Replies:** 0\
**Last updated:** [August 10, 2021, 9:44pm UTC](https://forums.powershell.org/t/private-module-function-not-found-when-running-all-test-scripts-and-piping-multiple-objects/17277 "2021-08-10T21:44:13Z")

</div>

I am working on a module that wraps the API of one of our partners. As such, most functions just pass values to Invoke-RestMethod and return the response. I am experiencing a strange issue where the private function tha…

---

## [Dont get the beforeAll](https://forums.powershell.org/t/dont-get-the-beforeall/16932)

<div class="topic-metadata">

**Author:** [@incognitotom](https://forums.powershell.org/u/incognitotom)\
**Replies:** 2\
**Last updated:** [July 13, 2021, 12:48pm UTC](https://forums.powershell.org/t/dont-get-the-beforeall/16932 "2021-07-13T12:48:12Z")

</div>

Hi, I am missing something, or something is broken, but I can only seem to get my tests to work if I duplicate the params in the beforeAll within the beforeDiscovery. From the documentation I read it as anything in the…

---

## [How to pass in values from file and test if deployed](https://forums.powershell.org/t/how-to-pass-in-values-from-file-and-test-if-deployed/16930)

<div class="topic-metadata">

**Author:** [@incognitotom](https://forums.powershell.org/u/incognitotom)\
**Replies:** 3\
**Last updated:** [June 27, 2021, 5:41pm UTC](https://forums.powershell.org/t/how-to-pass-in-values-from-file-and-test-if-deployed/16930 "2021-06-27T17:41:51Z")

</div>

Hi. I’m trying to validate the infrastructure being deployed into Azure. What i am looking to do is populate a JSON file with values and then pull the values in, and then check that what is listed in the JSON has been d…

---

## [How to show Pester result in VS code](https://forums.powershell.org/t/how-to-show-pester-result-in-vs-code/16864)

<div class="topic-metadata">

**Author:** [@MikeZhang307](https://forums.powershell.org/u/MikeZhang307)\
**Replies:** 2\
**Last updated:** [June 23, 2021, 12:21pm UTC](https://forums.powershell.org/t/how-to-show-pester-result-in-vs-code/16864 "2021-06-23T12:21:23Z")

</div>

Dear, I googled several times. but so far, my pester test can not be shown in the sidebar. it is difficult to find the failed test case if the output message is long. now I publish pester test results in Jenkins and Az…

---

## [Running Pester test from within a module fails to test a private function](https://forums.powershell.org/t/running-pester-test-from-within-a-module-fails-to-test-a-private-function/16849)

<div class="topic-metadata">

**Author:** [@Marc013](https://forums.powershell.org/u/Marc013)\
**Replies:** 3\
**Last updated:** [June 22, 2021, 5:34pm UTC](https://forums.powershell.org/t/running-pester-test-from-within-a-module-fails-to-test-a-private-function/16849 "2021-06-22T17:34:47Z")

</div>

Can anyone please tell me what I am doing wrong? I’m creating my own pwsh module with some functions I find handy. One of those functions is for generating unit test and code coverage HTML reports (New-UnitTestReport). …

---

## [TestDrive and file creation dates](https://forums.powershell.org/t/testdrive-and-file-creation-dates/16259)

<div class="topic-metadata">

**Author:** [@jbrusoe](https://forums.powershell.org/u/jbrusoe)\
**Replies:** 3\
**Last updated:** [June 18, 2021, 4:30am UTC](https://forums.powershell.org/t/testdrive-and-file-creation-dates/16259 "2021-06-18T04:30:25Z")

</div>

I have a function that selects certain files based on when they were created, but I’m struggling with a way to create and test this function with TestDrive because of the date criteria. Does anybody have any suggestions …

---

## [Pester inheritance](https://forums.powershell.org/t/pester-inheritance/16847)

<div class="topic-metadata">

**Author:** [@guytwig](https://forums.powershell.org/u/guytwig)\
**Replies:** 0\
**Last updated:** [June 17, 2021, 7:58am UTC](https://forums.powershell.org/t/pester-inheritance/16847 "2021-06-17T07:58:28Z")

</div>

Hi, Is there a way to inherit\\extend test cases? More detailed: I have a TestBase class which have common functionalities and modules for all the tests that inherit it. Each inherited test calls “Run” function. The r…

---

## [Virus Scanner Gives False Positive with tests.ps1 File](https://forums.powershell.org/t/virus-scanner-gives-false-positive-with-tests-ps1-file/16475)

<div class="topic-metadata">

**Author:** [@jbrusoe](https://forums.powershell.org/u/jbrusoe)\
**Replies:** 3\
**Last updated:** [May 17, 2021, 9:37pm UTC](https://forums.powershell.org/t/virus-scanner-gives-false-positive-with-tests-ps1-file/16475 "2021-05-17T21:37:20Z")

</div>

I’m trying to run Pester code that I wrote and have run many times over the past year. However, it just started to give me this warning about being caught by the virus scanner. This is all my own code that I have written…

---

## [How to make the output in the pipeline appear on the console when running pester](https://forums.powershell.org/t/how-to-make-the-output-in-the-pipeline-appear-on-the-console-when-running-pester/15440)

<div class="topic-metadata">

**Author:** [@andyao](https://forums.powershell.org/u/andyao)\
**Replies:** 0\
**Last updated:** [December 28, 2020, 11:53pm UTC](https://forums.powershell.org/t/how-to-make-the-output-in-the-pipeline-appear-on-the-console-when-running-pester/15440 "2020-12-28T23:53:50Z")

</div>

By default, the output in the pipeline is hidden,But sometimes I really want to know the output at that time. Of course, I knew I could add additional commands, such as write-host or out-default. But does Pester itself…

---

## [when use dbachecks, it has error: unable to find type \[Pester.outputtypes\]](https://forums.powershell.org/t/when-use-dbachecks-it-has-error-unable-to-find-type-pester-outputtypes/15285)

<div class="topic-metadata">

**Author:** [@hshi](https://forums.powershell.org/u/hshi)\
**Replies:** 4\
**Last updated:** [December 2, 2020, 8:08am UTC](https://forums.powershell.org/t/when-use-dbachecks-it-has-error-unable-to-find-type-pester-outputtypes/15285 "2020-12-02T08:08:00Z")

</div>

the code I’ve entered is below: invoke-dbcCheck Result: Unable to find type \[Pester.OutputTypes\]. At line:219 char:9 \[Pester.OutputTypes\]$Show = ‘All’ CategoryInfo : InvalidOperation: (Pester.OutputTypes:TypeName…

---

## [Mocking Invoke-Command](https://forums.powershell.org/t/mocking-invoke-command/15293)

<div class="topic-metadata">

**Author:** [@abok\_d](https://forums.powershell.org/u/abok_d)\
**Replies:** 2\
**Last updated:** [November 27, 2020, 12:29pm UTC](https://forums.powershell.org/t/mocking-invoke-command/15293 "2020-11-27T12:29:50Z")

</div>

How would one go about properly mocking ‘Invoke-Command’ for this example? This is just a part of my function that I’m trying to test at the moment, the second part removes the package if there is a match (calling ‘Invo…

---

## [Have Pester not collect Non-Terminating errors](https://forums.powershell.org/t/have-pester-not-collect-non-terminating-errors/15277)

<div class="topic-metadata">

**Author:** [@mikemayops](https://forums.powershell.org/u/mikemayops)\
**Replies:** 1\
**Last updated:** [November 24, 2020, 10:39pm UTC](https://forums.powershell.org/t/have-pester-not-collect-non-terminating-errors/15277 "2020-11-24T22:39:30Z")

</div>

Hi All, I’m running into this issue where I’m casting a variable to \[int\] type, but unfortunately for me the data being fed is not always in a correct format to succeed 100%. I’ve created a basic test to illustrate my is…

[Next page](https://forums.powershell.org/c/pester/8.md?page=1)
