FunctionsToExport/Function_Get-VHDChildRelations.ps1
Function Get-VHDChildRelations { [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 ) Begin { [Collections.Generic.List[object]]$PathCollection = @() } Process { $Location | ForEach-Object { Get-ChildItem $_ -Filter '*.vhd*' -Recurse | Select-Object -ExpandProperty FullName | ForEach-Object { $PathCollection.Add($_) } } } End { # Get All VHDs [Collections.Generic.List[object]]$VHDs = Get-VHD -Path $PathCollection # Resolve Parent / Child Relation $SelectObjectProperty = @( '*' @{ Name = "ChildRelations" Expression = { $Path = $_.Path $VHDs | Where-Object { $_.ParentPath -eq $Path } | Select-Object $SelectObjectProperty } } ) # Output $VHDs | Select-Object $SelectObjectProperty | Where-Object { $_.Path -like $Path } | Select-Object -ExpandProperty ChildRelations } } |