How to get unit quantity and item quantity from a Vault item bom

Description

When using Get-VaultItemBom only the total Quantity is currently available on the returned bom rows. The only way to get around this is to read those values from the item bom, via Vault API. 

The following function gets a powerVault item bom and adds those values from the Vault item bom to it as Bom_ItemQuantity and Bom_UnitQuantity

function GetVaultItemBomWithQuantities {
    param (
        $Number,
        [switch]$Recursive
    )

    if (-not $Number) {
        return @()
    }

    $item = Get-VaultItem -Number $Number
    $bomRow = Get-VaultItemBom -Number $Number
    $itemAssocs = $vault.ItemService.GetItemBOMAssociationsByItemIds(@($item.Id), $false)

    $bom = [System.Collections.ArrayList]::new()
    foreach ($position in $bomRow) {
        $currentRowAssoc = $itemAssocs | Where-Object { $_.CldItemID -eq $position.Id -and $_.PositionNum -eq $position.Bom_PositionNumber }
        Add-Member -InputObject $position -MemberType NoteProperty -Name Bom_ItemQuantity -Value $currentRowAssoc.InstCount
        Add-Member -InputObject $position -MemberType NoteProperty -Name Bom_UnitQuantity -Value $currentRowAssoc.UnitSize
        $null = $bom.Add($position)
        if ($Recursive) {
            $subBoms = GetVaultItemBomWithQuantities -Number $position._Number -Recursive
            if ($subBoms -and $subBoms.Count -gt 1) {
                $null = $bom.AddRange($subBoms)
            }
            elseif ($subBoms) {
                $null = $bom.Add($subBoms)
            }
        }
    }

    return $bom
}