Problem

I was trying to parameterize a Pester script. The script looked like this:

param (
   [string]$ComputerName,
   [string]$IPAddress
)

write-dbg "$ComputerName: "
write-dbg "$IPAddress: "

Describe "$ComputerName is visible" {

    "It is ping-able" {
       {test-connection $ComputerName -count 1} | Should Not Throw

       $(test-connection $ComputerName -count 1 | Measure-Object).count | Should Be 1
    }

}

…but passing the parameters wasn’t working.

Solution

The problem was that I was calling the script as follows

$ Invoke-Pester  @{PAth = c:\pester\diagnostics\simple\StandardDomainContoller.tests.ps1; Parameters=@{ComputerName = "server1.here.co.uk";IPAddress = "17.6.5.1""}}

…and the Path variable needs quotes:

$ Invoke-Pester  @{PAth = 'c:\pester\diagnostics\simple\StandardDomainContoller.tests.ps1'; Parameters=@{ComputerName = "server1.here.co.uk";IPAddress = "17.6.5.1""}}