function Test-HaveAccountCount { <# .SYNOPSIS Test the count of accounts for a user/url. .DESCRIPTION Intended to be used in conjunction with Test-Should function. .PARAMETER result The result of the Invoke-WebRequest containing Html to test against. .PARAMETER expect The number of accounts expected to be in the $result. .EXAMPLE $passedTest = (Test-Should -Result $webResponse -Predicate ${function:Test-HaveAccountCount} 3) .NOTES Returns a bool of success and/or error message. #> [CmdletBinding()] [OutputType([System.Boolean])] [OutputType([System.String])] param( $result, $expect ) try { $html = $result.Content $accountsCount = ([regex]::Matches($html, 'class="account ')).count if($expect -ne $accountsCount) { $false "Number of accounts doesn't match. Expected $expect but found $accountsCount." } else { $true } } catch { $false "Error occured inside test! Exception: $_" } }