src/Install-CciModule.ps1

function Install-CciModule {
<#
.SYNOPSIS
    Install a CCI module from a tenant feed.
.PARAMETER Name
    Module name (required). Wildcards are not supported by Install-PSResource.
.PARAMETER Version
    Optional version constraint passed to Install-PSResource.
.PARAMETER Tenant
    Optional. Tenant feed to install from. If omitted, uses defaultFeed from
    Get-CciGetConfig.
.PARAMETER Scope
    CurrentUser (default) or AllUsers.
.EXAMPLE
    Install-CciModule Cci.Citrix
.EXAMPLE
    Install-CciModule Cci.Common -Tenant ccidev -Version 0.1.0
#>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0)]
        [string]$Name,
        [string]$Version,
        [string]$Tenant,
        [ValidateSet('CurrentUser','AllUsers')]
        [string]$Scope = 'CurrentUser',
        [switch]$Reinstall,
        [switch]$TrustRepository
    )

    if (-not $Tenant) { $Tenant = (Get-CciGetConfig).defaultFeed }
    $feed     = (_Resolve-CciGetFeed -Tenant $Tenant)[0]
    $repoName = _Get-CciGetRepositoryName -FeedName $feed.name

    # v2 feeds serve tenant-prefixed names; let consumers say 'vmware' or 'Cci.Vmware'.
    $resolved = _Resolve-CciModuleName -Name $Name -Feed $feed
    if ($resolved -ne $Name) { Write-Host "cciget: '$Name' -> '$resolved' on feed '$($feed.name)'." }
    $Name = $resolved

    if (-not (Get-PSResourceRepository -Name $repoName -ErrorAction SilentlyContinue)) {
        Connect-CciGet -Tenant $feed.name | Out-Null
    }

    # Connect-CciGet sets this to 'blob' when feed auth is unavailable (no Azure
    # DevOps entitlement) but the tenant distribution store is reachable.
    if ($Script:CciGetSource -eq 'blob') {
        $blobCtx = _Connect-CciBlobStore -Feed $feed
        if (-not $blobCtx) { throw "cciget: the tenant distribution store is not reachable for '$($feed.name)'." }
        $index = _Get-CciBlobModuleIndex -Feed $feed -Context $blobCtx
        if (-not $index) { throw "cciget: no module index in the tenant distribution store for '$($feed.name)'." }
        _Install-CciModuleFromBlob -Name $Name -Feed $feed -Context $blobCtx -Index $index `
            -Version $Version -Scope $Scope -Reinstall:$Reinstall
        return
    }

    $params = @{
        Name       = $Name
        Repository = $repoName
        Scope      = $Scope
    }
    if ($Version)         { $params.Version         = $Version }
    if ($Reinstall)       { $params.Reinstall       = $true }
    if ($TrustRepository) { $params.TrustRepository = $true }

    Install-PSResource @params
}