Private/ConvertFrom-AirTableRecord.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function ConvertFrom-AirTableRecord
{
    param
    (
        [Parameter(Mandatory)]
        [string]$TableName,

        [Parameter(Mandatory, ValueFromPipeline)]
        [PSCustomObject[]]$InputObject
    )

    process
    {
        foreach ($Item in $InputObject)
        {
            $Properties = [Ordered]@{ }
            $Item.Fields.PSObject.Properties.ForEach{ $Properties.Add($_.Name, $_.Value) }
            $Properties.AirTableRecordID = $Item.ID
            $Properties.AirTableCreatedTime = $Item.CreatedTime
            $Properties.PSTypeName = "AirTable.Record.$TableName"
        }

        [PSCustomObject]$Properties
    }
}