Private/Invoke-ResolveDependency.ps1

<#
.SYNOPSIS
    Parse installed module based to get dependent module
.PARAMETER InstalledLocation
    Path to installed location of the module
.PARAMETER Credential
    Repository Credential
.PARAMETER Repository
    Name of the repository
#>

function Invoke-ResolveDependency {
    [CmdLetBinding()]
    param (        
        [Parameter(Mandatory = $true, HelpMessage = "Path to installed location of the module")]
        [string] $InstalledLocation,

        [Parameter(Mandatory=$false, HelpMessage = "Repository Credential")]
        [PSCredential] $Credential = $null,

        [Parameter(Mandatory=$false, HelpMessage = "Repository name")]
        [string] $Repository = $null,

        [Parameter(Mandatory=$false, HelpMessage = "Repository name")]
        [string[]] $AllowPrereleaseList = @('Psql')
    )
    $ErrorActionPreference = 'Stop'    
    Write-Debug '-- begin - Invoke-ResolveDependency --'
    Write-Debug "InstalledLocation: $InstalledLocation"

    $psdFiles = Get-ChildItem -Path $InstalledLocation -Filter *.psd1 -File
    foreach ($onePsdFile in $psdFiles) {
        $Manifest = Import-PowershellDataFile -LiteralPath $onePsdFile.FullName

        foreach ($onePrivateData in $Manifest.PrivateData) {
            foreach ($onePSData in $onePrivateData.PSData) {
                foreach ($oneExternalModuleDependencies in $onePSData.ExternalModuleDependencies) {
                   $PSGAlleryInstallParam =  Get-VersionParamHelper `
                                            -Module $oneExternalModuleDependencies

                   #$PSGAlleryInstallParam += @{
                   # Repository = 'PSGallery'
                   # Credential = $null
                   #}

                   if($AllowPrereleaseList -contains $PSGAlleryInstallParam.Name) {
                       $PSGAlleryInstallParam += @{
                          $AllowPrerelease = $True
                       }
                   }

                   Write-Verbose "Install prerequisity from PSGallery:"
                   Write-Debug (ConvertTo-Json -InputObject $PSGAlleryInstallParam)
                   Install-OriAzBopPrerequisity @PSGAlleryInstallParam `
                   -SkipImport:$True `
                   -AllowClobber:$True `
                   -SkipPublisherCheck:$true `
                   -Verbose:$VerbosePreference `
                   -Debug:$DebugPreference | Out-Null
                    
                   #Invoke-ModuleInstall @PSGAlleryInstallParam `
                   #-Verbose:$VerbosePreference `
                   #-Debug:$DebugPreference | Out-Null

                }
            }
        }

        foreach ($oneModule in $Manifest.RequiredModules) {
            $InstallParam = Get-VersionParamHelper -Module $oneModule

            if($null -ne $Credential) {
                $InstallParam += @{Credential = $Credential}
            }
            if($null -ne $Repository) {
                $InstallParam += @{Repository = $Repository}
            }
                
            Write-Debug (ConvertTo-Json -InputObject $InstallParam)
            Invoke-ModuleInstall @InstallParam | Out-Null
                    
        }  
    }
    Write-Debug '-- end - Invoke-ResolveDependency --'
}