Configurations/PowerShellLab/dev-pester.ps1

Describe SRV1 -Skip {

    $VMName = "$($prefix)SRV1"
    Try {
        $srv1 = New-PSSession -VMName $VMName -Credential $cred -ErrorAction Stop
        $all += $srv1
        Invoke-Command $prep -Session $srv1

        It "[SRV1] Should -Belong to the $domain domain" {
            $test = Invoke-Command { Get-CimInstance -ClassName win32_computersystem -Property domain } -Session $SRV1
            $test.domain | Should -Be $domain
        }

        It '[SRV1] Should have an IP address of 192.168.3.50' {
            $i = Invoke-Command -ScriptBlock { Get-NetIPAddress -InterfaceAlias 'Ethernet' -AddressFamily IPv4 } -Session $SRV1
            $i.ipv4Address | Should -Be '192.168.3.50'
        }
        $dns = Invoke-Command { Get-DnsClientServerAddress -InterfaceAlias ethernet -AddressFamily IPv4 } -Session $SRV1
        It '[SRV1] Should have a DNS server configuration of 192.168.3.10' {
            $dns.ServerAddresses -contains '192.168.3.10' | Should -Be 'True'
        }

        It '[SRV1] Should -Be running Windows Server 2016' {
            $test = Invoke-Command { Get-CimInstance -ClassName win32_OperatingSystem -Property caption } -Session $srv1
            $test.caption | Should -BeLike '*2016*'
        }

        <# It "[SRV1] Should pass Test-DSCConfiguration" {
            Invoke-Command { Test-DscConfiguration -WarningAction SilentlyContinue } -Session $srv1 | Should -Be "True"
        } #>

    }
    Catch {

    }
} #SRV1


Describe SRV2 -Skip {

    $VMName = "$($prefix)SRV2"
    Try {
        $SRV2 = New-PSSession -VMName $VMName -Credential $cred -ErrorAction Stop
        $all += $srv2
        Invoke-Command $prep -Session $srv2

        It "[SRV2] Should -Belong to the $domain domain" {
            $test = Invoke-Command { Get-CimInstance -ClassName win32_computersystem -Property domain } -Session $SRV2
            $test.domain | Should -Be $domain
        }

        It '[SRV2] Should have an IP address of 192.168.3.51' {
            $i = Invoke-Command -ScriptBlock { Get-NetIPAddress -InterfaceAlias 'Ethernet' -AddressFamily IPv4 } -Session $SRV2
            $i.ipv4Address | Should -Be '192.168.3.51'
        }
        $dns = Invoke-Command { Get-DnsClientServerAddress -InterfaceAlias ethernet -AddressFamily IPv4 } -Session $SRV2
        It '[SRV2] Should have a DNS server configuration of 192.168.3.10' {
            $dns.ServerAddresses -contains '192.168.3.10' | Should -Be 'True'
        }

        It '[SRV2] Should have the Web-Server feature installed' {
            $feature = Invoke-Command { Get-WindowsFeature -Name web-server } -Session $SRV2
            $feature.Installed | Should -Be $True
        }

        It '[SRV2] Should have a sample web service file' {
            $file = Invoke-Command { Get-Item C:\MyWebServices\firstservice.asmx } -Session $SRV2
            $file.name | Should -Be 'firstservice.asmx'
        }
        It '[SRV2] Should have a WebApplication called MyWebServices' {
            $app = Invoke-Command { Try { Get-WebApplication -Name MyWebServices -ErrorAction stop } Catch {} } -Session $SRV2
            $app.path | Should -Be '/MyWebServices'
            $app.PhysicalPath | Should -Be 'c:\MyWebServices'
        }

        It '[SRV2] Should -Be running Windows Server 2016' {
            $test = Invoke-Command { Get-CimInstance -ClassName win32_OperatingSystem -Property caption } -Session $srv2
            $test.caption | Should -BeLike '*2016*'
        }

        <# It "[SRV2] Should pass Test-DSCConfiguration" {
            Invoke-Command { Test-DscConfiguration -WarningAction SilentlyContinue } -Session $srv2 | Should -Be "True"
        } #>

    }
    Catch {

    }
} #SRV2

#>


Describe SRV3 -Skip {
    BeforeAll {



            $LabData = Import-PowerShellDataFile -Path $PSScriptRoot\VMConfigurationData.psd1
            $Secure = ConvertTo-SecureString -String "$($LabData.AllNodes.LabPassword)" -AsPlainText -Force
            $Domain = $LabData.AllNodes.DomainName
            $wgCred = New-Object PSCredential 'administrator', $secure
            $prefix = $LabData.NonNodeData.Lability.EnvironmentPrefix
            $VMName = "$($prefix)$Computername"



    }

    $VMName = "$($prefix)SRV3"
    Try {
        $srv3 = New-PSSession -VMName $VMName -Credential $wgCred -ErrorAction Stop
        $all += $srv3
        Invoke-Command $prep -Session $srv3

        It '[SRV3] Should respond to WSMan requests' {
            $srv3.Computername | Should -Be $VMName
        }

        It '[SRV3] Should have an IP address of 192.168.3.60' {
            $r = Invoke-Command { Get-NetIPAddress -InterfaceAlias Ethernet -AddressFamily IPv4 } -Session $srv3
            $r.IPv4Address | Should -Be '192.168.3.60'
        }

        It '[SRV3] Should -Belong to a Workgroup' {
            $sys = Invoke-Command { Get-CimInstance Win32_computersystem } -Session $srv3
            $sys.Domain | Should -Be 'Workgroup'
        }

        It '[SRV3] Should -Be running Windows Server 2019' {
            $test = Invoke-Command { Get-CimInstance -ClassName win32_OperatingSystem -Property caption } -Session $srv3
            $test.caption | Should -BeLike '*2019*'
        }

        <# It "[SRV3] Should pass Test-DSCConfiguration" {
            Invoke-Command { Test-DscConfiguration -WarningAction SilentlyContinue } -Session $srv3 | Should -Be "True"
        } #>

    }
    Catch {

    }
}

#>


Describe Win10 -Skip {

    $VMName = "$($prefix)Win10"
    $rsat = @(
        'Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0',
        'Rsat.BitLocker.Recovery.Tools~~~~0.0.1.0',
        'Rsat.CertificateServices.Tools~~~~0.0.1.0',
        'Rsat.DHCP.Tools~~~~0.0.1.0',
        'Rsat.Dns.Tools~~~~0.0.1.0',
        'Rsat.FailoverCluster.Management.Tools~~~~0.0.1.0',
        'Rsat.FileServices.Tools~~~~0.0.1.0',
        'Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0',
        'Rsat.IPAM.Client.Tools~~~~0.0.1.0',
        'Rsat.ServerManager.Tools~~~~0.0.1.0'
    )

    Try {
        $cl = New-PSSession -VMName $VMName -Credential $cred -ErrorAction Stop
        $all += $cl
        Invoke-Command $prep -Session $cl

        It "[WIN10] Should -Belong to the $Domain domain" {
            $test = Invoke-Command { Get-CimInstance -ClassName win32_computersystem -Property domain } -Session $cl
            $test.domain | Should -Be $Domain
        }

        It '[WIN10] Should -Be running Windows 10 Enterprise' {
            $test = Invoke-Command { Get-CimInstance -ClassName win32_OperatingSystem -Property version, caption } -Session $cl
            $test.caption | Should -BeLike '*Enterprise*'
        }

        It '[Win10] Should have an IP address of 192.168.3.100' {
            $i = Invoke-Command -ScriptBlock { Get-NetIPAddress -InterfaceAlias 'Ethernet' -AddressFamily IPv4 } -Session $cl
            $i.ipv4Address | Should -Be '192.168.3.100'
        }

        $dns = Invoke-Command { Get-DnsClientServerAddress -InterfaceAlias ethernet -AddressFamily IPv4 } -Session $cl
        It '[Win10] Should have a DNS server configuration of 192.168.3.10' {
            $dns.ServerAddresses -contains '192.168.3.10' | Should -Be 'True'
        }

        $pkg = Invoke-Command { $using:rsat | ForEach-Object { Get-WindowsCapability -Online -Name $_ } } -Session $cl
        $RSATStatus = '{0}/{1}' -f ($pkg.where({ $_.state -eq 'installed' }).Name).count, $rsat.count
        It "[Win10] Should have RSAT installed [$RSATStatus]" {
            # write-host ($pkg | Select-object Name,DisplayName,State | format-list | Out-String) -ForegroundColor cyan
            $pkg | Where-Object { $_.state -ne 'installed' } | Should -Be $Null
        }

        <# It "[Win10] Should pass Test-DSCConfiguration" {
            Invoke-Command { Test-DscConfiguration -WarningAction SilentlyContinue } -Session $cl | Should -Be "True"
        } #>

    }
    Catch {

    }
} #client