Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
90 views

I'm exploring Pester for unit testing my PowerShell scripts, and I'm running into a mocking issue. I dot-source my functions like this: . "$PSScriptRoot\tz-docker.functions.ps1" But my ...
Tech with Thiru's user avatar
4 votes
1 answer
117 views

I have a PowerShell script for setting up a website in IIS. It includes the following function: function Set-IisWebsiteBinding ( [Parameter(Mandatory = $true)] [string]$SiteName, [...
Simon Elms's user avatar
  • 20.3k
1 vote
1 answer
154 views

I am receiving the following error when trying get this pester test to work for a function that receives a pipeline parameter. "An error occured running Pester: The input object cannot be bound ...
Kurtis's user avatar
  • 37
1 vote
1 answer
27 views

I have been unable to get the mock for New-Object to work. Below is the function and the test inline. Import-Module ImportExcel -Force function Clear-ExcelWorksheet { [CmdletBinding()] param (...
Kurtis's user avatar
  • 37
0 votes
0 answers
106 views

I am using VS Code for my PowerShell development. I have version 5.1 of PowerShell and version 1.95.3 of VS Code. I have the Pester extension installed in VS Code (version v2023.7.7). Until recently, ...
gerard's user avatar
  • 1,040
0 votes
1 answer
185 views

I would like to mock New-AzStorageContext to return a value that can be used as the DestContext parameter of the function Start-AzStorageBlobCopy. I have tried New-MockObject of Microsoft.WindowsAzure....
Tim Bassett's user avatar
  • 1,238
0 votes
1 answer
98 views

Pester 5.6.1 Powershell 7.4.5 Here's the deal. I have data that I am loading in the BeforeDiscovery. I can reference all the variables within at the Run stage...no problem there. Even the string ...
Scott Newman's user avatar
0 votes
1 answer
64 views

This Pester test: BeforeAll { function Get-HtmlFileDetail { param ( [string[]]$Path = 'E:\Domains', [string[]]$Include = 'Alive*.html' ) return Get-...
bravogolfgolf's user avatar
1 vote
1 answer
156 views

Synopsis: When trying to calling New-MockObject -Type 'Config' where Config is a class defined in another psm1 file, I get the following error PSInvalidCastException: Cannot convert the "Config&...
Devin Gleason Lambert's user avatar
2 votes
1 answer
282 views

I have the following Pester Test-script: function Get-Name{ return "TestObject" } Describe{ BeforeAll{ $Script:ObjectID $API::[API]::New() } It 'Get ...
user3127554's user avatar
3 votes
1 answer
375 views

What's the correct way to compare hashtables in Pester tests? i.e. the following gives the error: InvalidResult: Expected System.Collections.Hashtable, but got System.Collections.Hashtable. $expected =...
JohnLBevan's user avatar
  • 24.8k
0 votes
0 answers
92 views

Why are the variables in my Context -ForEach cases not being passed to the It blocks underneath the Context? I have this code in my test file. BeforeAll { Import-Module Pester Import-Module ...
Martin's user avatar
  • 545
0 votes
2 answers
182 views

Whenever I am trying to use parameter value in BeforeDiscovery under Context in Pester test case it's giving below error. Please help me. Error:: ##[error] [-] Discovery in D:\a\1\s\deploymenttest\...
Abhijit's user avatar
  • 27
0 votes
0 answers
110 views

I am building a PowerShell module using the PSModuleDevelopment's MiniModule template generator. It makes a project that looks like this: PROJECT_ROOT/ ├─ the_module_name/ │ ├─ internal/ │ │ ├─ ...
Mark Mascolino's user avatar
3 votes
1 answer
549 views

I've found a lot of questions about mocking a function (method) within a PowerShell class. The question I have (and can't find an answer for) is, is it possible to mock a cmdlet call that is contained ...
MVogwell's user avatar
1 vote
1 answer
102 views

I not able to get Pester 5.5.0 Mocks working. I have defined a Mock for Get-Date in the Describe block but when the tests run it does not appear to be invoked. MyFunction.ps1 function Get-CurrentDate {...
joe-jeff's user avatar
  • 336
1 vote
1 answer
461 views

I've started reading up on the Pester framework and I could use some thinking power on how to handle my situation. We have several existing PowerShell scripts. Simple example MyScript.ps1 (pseudo code)...
tutu's user avatar
  • 695
1 vote
1 answer
126 views

I have some old Pester v4 tests that are failing when I try to run them in Pester v5. With Pester v4 I read that once Mock is called it will continue to apply for the rest of the Describe block, even ...
Simon Elms's user avatar
  • 20.3k
3 votes
2 answers
437 views

I am creating a PowerShell module that defines a class. For example: class MyClass { [string] $Name } If I put the class definition directly in the psm1 file then everything works fine. However, ...
deadlydog's user avatar
  • 24.8k
0 votes
0 answers
364 views

I want to create a test with Pester. I have to create some files and then read them with a filter. The problem I get is when I use $PSScriptRoot. If I run the test in the Windows PowerShell ISE, it is ...
Enrico's user avatar
  • 6,872
0 votes
1 answer
277 views

I want to create a PowerShell script that can delete a bunch of file in a given paths following a particular match (in the following example all the files that contain TMP). This is the function: ...
Enrico's user avatar
  • 6,872
0 votes
1 answer
124 views

still trying to learn Pester, I got a snippet from ChatGPT: function Get-EvenNumbers { param( [Parameter(Mandatory=$true)] [int]$start, [Parameter(Mandatory=$true)] [int]$end ) $evenNumbers = @() ...
Purclot's user avatar
  • 583
0 votes
1 answer
105 views

I currently have a PowerShell module that extends another module. Basically, my new module re-implements one Function to provide custom behavior for a specific customer: Base Module - Implements 12 ...
JeremySeattle's user avatar
0 votes
1 answer
477 views

I want to write a test in PowerShell with Pester 5.4.0 to check whether a specific exception type has been thrown inside a script block. It should be fairly easy, but I am somehow not doing it right. ...
hyt's user avatar
  • 992
3 votes
2 answers
1k views

I would like to define stand-alone functions in my PowerShell script and be able to Pester test the functions without executing the rest of the script. Is there any way to do this without defining the ...
successhawk's user avatar
  • 3,401

1
2 3 4 5
7