Functions/PSWebConfig/Test-PSWebConfig.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
48
49
50
51
52
53
54
55
56
57
<#
.SYNOPSIS
    Tests all URI and ConnectionStrings from web or application configuration.

.DESCRIPTION
    The cmdlet fetches all ConnectionString and service endpoint URIs
    from a configuration xml and executes a test against them on a
    local or remote machine.

    If -IncludeAppSettings switch is defined, it will include any URI or
    ConnectionStrings to the tests.

.PARAMETER InputObject
    Mandatory - Parameter to pass a PSWebConfig object

.PARAMETER Session
    Optional - PSSession to execute configuration test

.PARAMETER IncludeAppSettings
    Optional - Switch to include URIs and ConnectionStrings from appSettings
    sections

.EXAMPLE
    Get-PSWebConfig -Path 'c:\intepub\wwwroot\testapp\' | Test-PSWebConfig

.EXAMPLE
    Get-WebSite | Get-PSWebConfig -Recurse | Test-PSWebConfig
#>

function Test-PSWebConfig {
    [CmdletBinding(DefaultParameterSetName="FromPipeLine")]
    param(
        [Parameter(
            ParameterSetName="FromPipeLine",
            ValueFromPipeLine=$true,
            Position=0,
            Mandatory=$true)]
        [psobject[]]$ConfigXml,

        [switch]$IncludeAppSettings,
        [System.Management.Automation.Runspaces.PSSession]$Session
    )
    process {
        Write-Verbose "Executing Test-PSWebConfig"

        if (-Not $ConfigXml.configuration) {
            Write-Verbose "InputObject is not a valid XML configuration, trying to get config XML."
            $ConfigXml = Get-PSWebConfig -InputObject $ConfigXml
        }

        Get-PSUri -ConfigXml $ConfigXml -IncludeAppSettings:$IncludeAppSettings |
        Test-PSUri -Session $Session

        Get-PSConnectionString -ConfigXml $ConfigXml -IncludeAppSettings:$IncludeAppSettings |
        Test-PSConnectionString -Session $Session
    }
}