paulomarquesc / AzureRmStorageTable

MIT License
40 stars 27 forks source link

Error 400: Bad Request when creating property with special characters #61

Closed RTTrickster closed 3 years ago

RTTrickster commented 3 years ago

I have a variable for an AD user account that contains the property of $User.DistinguishedName, representing a string equivalent to ' CN=username,OU=User OU,DC=MyDomain,DC=com '.

When attempting to write this value to a Table row using the standard code;

Add-azTableRow -table $table -partitionKey $partitionKey -rowKey ([guid]::NewGuid().tostring()) -property @{ 'Distinguished Name' = $User.DistinguishedName }

I am presented with the error:

Exception calling "Execute" with "1" argument(s): "The remote server returned an error: (400) Bad Request." At C:\Program Files\WindowsPowerShell\Modules\AzTable\2.0.3\AzureRmStorageTableCoreHelper.psm1:249 char:10

  • ... return ($Table.Execute([Microsoft.Azure.Cosmos.Table.TableOperat ...
  • 
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : StorageException

If I repeat the same command with a different plain text value from the same variable, such as $User.name, it works perfectly fine.

I reviewed https://docs.microsoft.com/en-us/rest/api/storageservices/Understanding-the-Table-Service-Data-Model?redirectedfrom=MSDN but there is no mention of disallowed characters in the property values.

RTTrickster commented 3 years ago

Update: Just realised this is also true of the variable $User.UserPrincipalName which represents string 'User@domain.com'.

So, no special characters allowed in property fields. Is this a bug? Have I missed some documentation?

RTTrickster commented 3 years ago

My apologies, I was chasing the wrong thing. I assumed my issue was with special characters in the property value, it was actually the fact that I had a space in the column name. After removing the space in the column name, the property value writes no problem.