FunctionsToExport/Function_Get-VHDChain.ps1
Function Get-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, [switch]$Passthru, [string]$Encoding = "UTF8" ) $Splat = @{ Path = Join-Path $Location ($Name + '.vhdchain.json') Encoding = $Encoding } if (-not ($Splat.Path | Get-Item -ErrorAction SilentlyContinue)) { throw 'Item ("{0}") does not exist' -f $Splat.Path } $Chain = Get-Content @Splat | ConvertFrom-Json if ($Index) { $Result = $Chain[$Index] } else { $Result = $Chain } if ($Passthru) { Get-VHD $Result.Path } else { $Result } } |