FunctionsToExport/Function_Mount-VHDChain.ps1

Function Mount-VHDChain {

    [CmdletBinding()]
    Param(

        [Parameter(ValueFromPipeline)]
        [ValidateScript({
                $Item = $_ | Get-Item -ErrorAction SilentlyContinue
                if (-not $Item) { throw 'Item ("{0}") does not exist' -f $_ }
                elseif ($Item.Attributes -notmatch "Directory") { throw 'Item ("{0}") is not a directory' -f $_ }
                $true
            }
        )]
        [string]$Location = $PWD,

        [ValidateNotNullOrEmpty()]
        [string]$Name = "VHDChain",   

        [int]$Index = -1

    )   

    $Chain = Get-VHDChain -Name $Name -Location $Location    
    $Path = $Chain[$Index].Path

    $DriveLetter = Get-VHD $Path -ErrorAction SilentlyContinue | Get-Disk -ErrorAction SilentlyContinue | Get-Partition -ErrorAction SilentlyContinue | Where-Object { $_.DriveLetter } | Select-Object -ExpandProperty DriveLetter
    if (-not $DriveLetter) { Mount-VHD -Path $Path | Out-Null }

    $DriveLetter = Get-VHD $Path | Get-Disk | Get-Partition | Where-Object { $_.DriveLetter } | Select-Object -ExpandProperty DriveLetter
    if ($DriveLetter) { $DriveLetter | ForEach-Object { '{0}:\' -f $_ } }

}