Public/WebSite.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
<#
.SYNOPSIS
    WebSite Settings
.DESCRIPTION
    Used To Determine if Website is Running Desired Settings
.PARAMETER Target
    The name of the Web Site to be Tested
.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 state { Should be 'Started' }
.EXAMPLE
   Website TestSite physicalPath { Should be 'C:\IIS\Files\index.html' }
.EXAMPLE
   Website TestSite binding { Should Match '*:80*' }
.EXAMPLE
   Website TestSite name { Should be 'testsite' }
 .EXAMPLE
   Website TestSite ID { Should be 1 }
.NOTES
    Assertions: Match, Be
#>

    function WebSite{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position=1)]
        [Alias('Name')]
        [string]$Target,
        
        [Parameter(Position=2)]
        [ValidateSet("bindings","name","ID","state","physicalPath")]
        [string]$Property,

        [Parameter(Mandatory, Position=3)]
        [scriptblock]$Should
    )
    
            $expression = {Get-WebSite -Name '$Target' -ErrorAction SilentlyContinue }
            
            $params = Get-PoshspecParam -TestName WebSite -TestExpression $expression @PSBoundParameters
            
            Invoke-PoshspecExpression @params
}