Public/WebSiteBinding.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<#
.SYNOPSIS
    WebSiteBinding Settings
.DESCRIPTION
    Used To Determine if Website is Running Desired Settings
.PARAMETER Target
    The name of the Web Site to be Tested
.PARAMETER Qualifier
 The qualifier to be used to further specify the test [http or https]
.PARAMETER Property
    The name of the Property of the Web Site to be Tested
.PARAMETER Should
    A Script Block defining a Pester Assertion.
.EXAMPLE
   WebSite TestSite http protocol { Should be "http" }
.EXAMPLE
   WebSite TestSite https bindingInformation { Should match '443' }
 .EXAMPLE
   WebSite TestSite https sslFlags { Should be 1 }
.NOTES
    Assertions: Match, Be
#>

    function WebSiteBinding{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position=1)]
        [Alias('Name')]
        [string]$Target,
        
        [Parameter(Position=2)]
        [ValidateSet("http","https")]
        [string]$Qualifier,
        
        [Parameter(Position=3)]
        [ValidateSet("sslFlags","protocol","bindingInformation")]
        [string]$Property,

        [Parameter(Mandatory, Position=4)]
        [scriptblock]$Should
    )
    
            $expression = {Get-WebBinding -Name '$Target' -protocol '$Qualifier' -ErrorAction SilentlyContinue }

            $params = Get-PoshspecParam -TestName WebSiteBinding -TestExpression $expression @PSBoundParameters
            
            Invoke-PoshspecExpression @params
}