tests/setup/install.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
58
59
60
61
git.exe clone -q https://github.com/PowerShell/DscResource.Tests

Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1"
Invoke-AppveyorInstallTask

[string[]]$PowerShellModules = @("Pester", 'posh-git', 'PSScriptAnalyzer')

$ModuleManifest = Test-ModuleManifest .\$($env:RepoName).psd1 -ErrorAction SilentlyContinue
$repoRequiredModules = $ModuleManifest.RequiredModules.Name
$repoRequiredModules += $ModuleManifest.PrivateData.PSData.ExternalModuleDependencies

If ($repoRequiredModules) { $PowerShellModules += $repoRequiredModules }

# This section is taken care of by Invoke-AppVeyorInstallTask
<#[string[]]$PackageProviders = @('NuGet', 'PowerShellGet')
 
# Install package providers for PowerShell Modules
ForEach ($Provider in $PackageProviders) {
    If (!(Get-PackageProvider $Provider -ErrorAction SilentlyContinue)) {
        Install-PackageProvider $Provider -Force -ForceBootstrap -Scope CurrentUser
    }
}#>


# Feature Installation

$serverFeatureList = @('Hyper-V')

If ($PowerShellModules -contains 'FailoverClusters') {
    $serverFeatureList += 'RSAT-Clustering-Mgmt', 'RSAT-Clustering-PowerShell'
}

$BuildSystem = Get-CimInstance -ClassName 'Win32_OperatingSystem'

ForEach ($Module in $PowerShellModules) {
    If ($Module -eq 'FailoverClusters') {
        Switch -Wildcard ($BuildSystem.Caption) {
            '*Windows 10*' {
                Write-Output 'Build System is Windows 10'
                Write-Output "Not Implemented"

                # Get FailoverCluster Capability Name and Install on W10 Builds
                $capabilityName = (Get-WindowsCapability -Online | Where-Object Name -like *RSAT*FailoverCluster.Management*).Name
                Add-WindowsCapability -Name $capabilityName -Online
            }

            Default {
                Write-Output "Build System is $($BuildSystem.Caption)"
                Install-WindowsFeature -Name $serverFeatureList -IncludeManagementTools | Out-Null
            }
        }
    }
    ElseIf ($Module -eq 'Pester') {
        Install-Module $Module -Scope AllUsers -Force -Repository PSGallery -AllowClobber -SkipPublisherCheck -RequiredVersion 4.9.0
        Import-Module $Module -RequiredVersion 4.9.0
    }
    else {
        Install-Module $Module -Scope AllUsers -Force -Repository PSGallery -AllowClobber
        Import-Module $Module
    }
}