Private/New-TableStorageRowEntity.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function New-TableStorageRowEntity {
    [CmdletBinding()]
    param(
        
        [Parameter(Mandatory = $true)]
        [AllowEmptyString()]
        [String]
        $PartitionKey,

        [Parameter(Mandatory = $true)]
        [AllowEmptyString()]
        [String]
        $RowKey,

        [Parameter(Mandatory = $true)]
        [PSCustomObject]
        $Data

    )
    try {

        # Create entity
        $Entity = New-Object -TypeName Microsoft.Azure.Cosmos.Table.DynamicTableEntity -ArgumentList $PartitionKey, $RowKey
    
        # Add properties
        $Entity.Properties.Add("Data", ($Data | ConvertTo-Json -Compress -Depth 10))

        <#
        $Pattern = "[^a-zA-Z0-9]"
        foreach ($Property in $Properties.psobject.Properties){
            if ($Property.Value -ne $null){
                $Name = $Property.Name -replace $Pattern,''
                $Entity.Properties.Add($Name, $Property.Value)
            }
        }
        #>

    
        Return $Entity
    }
    catch {
        throw $_
    }
}