CmdLets/Initialize-PreReqs.ps1

Function Initialize-PreReqs 
 {


    Write-Host "Checking PreReqs"
    
    $PackageSources = @(
        @{
            Name="nuget.org"
            Location="https://www.nuget.org/api/v2/"
            ProviderName="Nuget"
            Debug=$False
            Trusted=$True
        },
        @{
            Name="PSGallery"
            Location="https://www.powershellgallery.com/api/v2"
            ProviderName="PowerShellGet"
            Debug=$False
            Trusted=$True
        }
    )

    Set-TLSVersion

    $PackageSources | ForEach-Object {
        if(!(get-packagesource -Name $_.Name -ErrorAction SilentlyContinue)){
            Write-Verbose "`tAdding Source: $($_.Name)"
            Register-PackageSource -Name $_.Name `
                -Location $_.Location `
                -ProviderName $_.ProviderName `
                -Debug:$_.Debug `
                -Trusted:$_.Trusted `
                -force `
                -ForceBootstrap | Out-Null
        } else {
            if ((Get-PackageSource -Name $_.Name).Trusted -ne $_.Trusted) {
                Write-Verbose "`tSetting Trusted: $($_.Name)"
                Set-PackageSource -Name $_.Name -Trusted:$_.Trusted -Force | Out-Null
            }
        }
    }

    if (!(test-path C:\ProgramData\chocolatey\bin\choco.exe)) {
        #Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    }

    $Modules = @(
        @{
            Name="Evergreen"
            Package=$false
            PostScriptBlocks=@(
                "Update-Evergreen -Force"
            )
        },
        @{
            Name="VcReDist"
            Package=$false
        }
    )
    ForEach ($Module in $Modules) { 
        if(!(Confirm-PreReq -PreReq $Module.Name -Package $Module.Package)) {
            Write-Verbose "`tAdding Module: $($Module.Name)"
            ForEach ($ScriptBlock in $Module.PreScriptBlocks) { 
                Write-Host $ScriptBlock
                Invoke-Command -ScriptBlock ([ScriptBlock]::Create($ScriptBlock)) -NoNewScope
            }
            Install-Prereq -PreReq $Module.Name -Package $Module.Package
            ForEach ($ScriptBlock in $Module.PostScriptBlocks) { 
                Write-Host $ScriptBlock
                Invoke-Command -ScriptBlock ([ScriptBlock]::Create($ScriptBlock)) -NoNewScope
            }
        }
    }

    <#
        Some Registry Settings are in HKEY_Classes_Root
        This adds the PSDrive so the rest of the script can interact with it
    #>

    If (!(Test-Path HKCR:\)){
        Write-Verbose "`tAdding PSDrive: HKCR"
        New-PSDrive -Name "HKCR" -PSProvider Registry -Root "HKEY_Classes_Root" | out-null
    }

    $PSModulePath = "C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\HorizonAutomation"
    If (!(Test-Path $PSModulePath)) { 
        New-ItemWrapper $PSModulePath
        $Modules = Get-Childitem (Join-Path $CommandPath "*.psm1")
        $Modules | Copy-Item -Destination $PSModulePath
    }

}