Private/Install-Icd.ps1

<#
    ProvisioningTools — Automates creation of Windows provisioning packages.
    Copyright (C) 2022 David Haymond.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <https://www.gnu.org/licenses/>.
#>


function Install-Icd {
    [CmdletBinding(
        SupportsShouldProcess = $true,
        ConfirmImpact = 'Medium'
    )]
    [OutputType([bool])]
    param(
        [switch] $Force
    )

    if ($Force -or $PSCmdlet.ShouldContinue(
        "The Windows Imaging and Configuration Designer is required but could not be found. " +
        "Would you like to install it?",
        "Install ICD"
    )) {
        $adksetup = Join-Path -Path $script:TEMPDIR -ChildPath 'adksetup.exe'
        $adkArgs = ('/features', 'OptionId.ImagingAndConfigurationDesigner', '/q', '/ceip', 'off')
        Invoke-WebRequest -Uri 'https://go.microsoft.com/fwlink/?linkid=2196127' -OutFile $adksetup
        Start-Process -FilePath $adksetup -ArgumentList $adkArgs -Wait
        return $true
    }

    return $false
}