1

I just created a method in powershell script as -

function Add-Entity() {
    [CmdletBinding()]
    param(
       $TableName,
       $PartitionKey,
       $RowKey,
       [String]$JsonString
    )


  $entity = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity -ArgumentList $PartitionKey, $RowKey
  $entity.Properties.Add("JsonStringProperty", $JsonString)
  $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity))
}

and I want to pass this complete jSon string as a parameter -

Add-Entity -TableName $myTableName -PartitionKey "ABC" -RowKey "XYZ" -JsonString {"TO":["[email protected]","[email protected]"],"CC":["[email protected]"],"BCC":[]}

Every time I try to compile, It gives me an error -

Unexpected token ':["abc@xyz".com"' in expression or statement

1 Answer 1

1

The issue is that the JSON uses double quotation marks to delimiter key and values and the same character (double quotation marks) is also used by Powershell for strings "wrapping".

You can use single quotation marks to wrap your hardcoded input json like so:

'{"TO":["[email protected]","[email protected]"],"CC":["[email protected]"],"BCC":[]}' 

So the statement would be:

Add-Entity -TableName $myTableName -PartitionKey "ABC" -RowKey "XYZ" -JsonString '{"TO":["[email protected]","[email protected]"],"CC":["[email protected]"],"BCC":[]}'
Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.