I have the following powershell script in order to update a value in table storage:
[string]$filter = `
[Microsoft.Azure.Cosmos.Table.TableQuery]::GenerateFilterCondition("Query",`
[Microsoft.Azure.Cosmos.Table.QueryComparisons]::Equal,"(Type = 'FTE')")
$user = Get-AzTableRow `
-table $cloudTable `
-customFilter $filter
# Change the entity.
$user.Query = "[{"filter":"(Type = 'FTE')"}]" // I need to include all these double quotes, single quotes
$user | Update-AzTableRow -table $cloudTable
I see this error: Unexpected token 'filter":"' in expression or statement. How do I resolve that?
CodePudding user response:
As an aside: you don't need explicit line continuations (via `
at the very end of a line) if the line at hand isn't syntactically a complete statement by itself. In other words: in your code, only the Get-AzTableRow
call requires it.
Your main problem is that you're trying to embed "
chars. inside a "..."
string without escaping, which causes your problem.
To escape "
chars. inside an expandable (double-quoted) string ("..."
), use `"
(or ""
):
Therefore:
$user.Query = "[{`"filter`":`"(Type = 'FTE')`"}]"
See also: The conceptual about_Quoting_Rules help topic.